Skip to content

jmenu.api

Contains functions used to wrangle the JAMIX API. This file can be imported and exposes the following functions:

* fetch_restaurant
* parse_items

The following constants are also exposed:

* API_URL

fetch_restaurant_items(rest, fetch_date, lang_code)

Return a list of MenuItems for specified Restaurant

Parameters:

Name Type Description Default
rest Restaurant

dataclass containing relevant restaurant information

required
fetch_date datetime

datetime object used to fetch the date specified menu

required
lang_code str

determines the language of the response currently supports codes 'fi' and 'en'

required

Returns:

Type Description
list[MenuItem]

parsed response content

Source code in src/jmenu/api.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def fetch_restaurant_items(
    rest: Restaurant,
    fetch_date: datetime,
    lang_code: str,
) -> list[MenuItem]:
    """Return a list of MenuItems for specified Restaurant

    Parameters:
        rest (Restaurant):
            dataclass containing relevant restaurant information
        fetch_date (datetime):
            datetime object used to fetch the date specified menu
        lang_code (str):
            determines the language of the response
            currently supports codes 'fi' and 'en'

    Returns:
        (list[MenuItem]):
            parsed response content
    """
    response = requests.get(
        f"{API_URL}/{rest.client_id}/{rest.kitchen_id}?lang={lang_code}&date={fetch_date.strftime('%Y%m%d')}",
        timeout=5,
    )
    data = response.json()
    return _parse_items(data, rest.relevant_menus)