Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate dish types #260

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Actions Status](https://github.com/TUM-Dev/eat-api/workflows/CI%2FCD/badge.svg)](https://github.com/TUM-Dev/eat-api/actions)


Simple static API for the canteens of the [Studierendenwerk München Oberbayern](http://www.studierendenwerk-muenchen-oberbayern.de) as well as some other canteens. By now, the following canteens are supported:
Simple static API for the canteens of the [Studierendenwerk München Oberbayern](https://www.studierendenwerk-muenchen-oberbayern.de) as well as some other canteens. By now, the following canteens are supported:

| Name | API-key | Address |
|:-------------------------------|:-------------------------------|:----------------------------------------------------------------------------------------------------------------------------|
Expand Down Expand Up @@ -111,7 +111,7 @@ The `canteens.json` and `label.json` are generated from the `Canteen` and `Label
- Parser for [OpenMensa](https://openmensa.org) ([GitHub](https://github.com/openmensa/openmensa))
- [Wilhelm Gastronomie im FMI Gebäude der TUM Garching](https://openmensa.org/c/773)
- [Konradhofer Catering - Betriebskantine IPP](https://openmensa.org/c/774)
- [Hunger | TUM.sexy](http://tum.sexy/hunger/) ([Github](https://github.com/mammuth/TUM.sexy))
- [Hunger | TUM.sexy](https://tum.sexy/hunger/) ([Github](https://github.com/mammuth/TUM.sexy))
- `FMeat.php` SDK ([GitHub](https://github.com/jpbernius/fmeat.php))
- [Telegram](https://telegram.org/) bot for [Channel t.me/lunchgfz](https://t.me/lunchgfz) ([GitLab](https://gitlab.com/raabf/lunchgfz-telegram))
- UWP-TUM-Campus-App ([Github](https://github.com/COM8/UWP-TUM-Campus-App))
Expand Down
65 changes: 59 additions & 6 deletions src/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def to_json_obj(self):
return {"base_price": self.base_price, "price_per_unit": self.price_per_unit, "unit": self.unit}

def __hash__(self) -> int:
# http://stackoverflow.com/questions/4005318/how-to-implement-a-good-hash-function-in-python
# https://stackoverflow.com/questions/4005318/how-to-implement-a-good-hash-function-in-python
return (hash(self.base_price) << 1) ^ hash(self.price_per_unit) ^ hash(self.unit)


Expand Down Expand Up @@ -97,7 +97,7 @@ def to_json_obj(self):
}

def __hash__(self) -> int:
# http://stackoverflow.com/questions/4005318/how-to-implement-a-good-hash-function-in-python
# https://stackoverflow.com/questions/4005318/how-to-implement-a-good-hash-function-in-python
return hash(self.students) ^ hash(self.staff) ^ hash(self.guests)


Expand Down Expand Up @@ -528,18 +528,71 @@ def to_api_representation(self) -> Dict[str, object]:
}


class DishType(ApiRepresentable, Enum):
def __init__(self, text: Dict[Language, str]):
self.text = text

@staticmethod
def custom(text: str):
class CUSTOM:
def __init__(self, text: str):
self.text = {Language.DE: text, Language.EN: text}

def to_json_obj(self):
return {
"name": "CUSTOM",
"text": json_util.dict_to_json_dict(self.text),
}

return CUSTOM(text)

CUSTOM = {Language.DE: "", Language.EN: ""}

PASTA = {Language.DE: "Pasta", Language.EN: "Pasta"}
PIZZA = {Language.DE: "Pizza", Language.EN: "Pizza"}
GRILLED = {Language.DE: "Grill", Language.EN: "Grilled"}
WOK = {Language.DE: "Wok", Language.EN: "Wok"}
STUDITOPF = {Language.DE: "Studitopf", Language.EN: "Studitopf"}
MEAT = {Language.DE: "Fleisch", Language.EN: "Meat"}
VEGETARIAN = {Language.DE: "Vegetarisch / fleischlos", Language.EN: "Vegetarian"}
VEGAN = {Language.DE: "Vegan", Language.EN: "Vegan"}
SOUP = {Language.DE: "Tagessupe", Language.EN: "Soup of the day"}
DAILY_DISH = {Language.DE: "Tagesgericht", Language.EN: "Daily dish"}
DESSERT = {Language.DE: "Dessert (Glas)", Language.EN: "Dessert (glass)"}
SIDE_DISH = {Language.DE: "Beilagen", Language.EN: "Side dishes"}
SALAD = {Language.DE: "Salat", Language.EN: "Salad"}
FRUITS = {Language.DE: "Obst", Language.EN: "Fruits"}
FISH = {Language.DE: "Fisch", Language.EN: "Fish"}
SWEET_DISH = {Language.DE: "Süßspeise", Language.EN: "Sweet dish"}
TRADITIONAL = {Language.DE: "Traditionelle Küche", Language.EN: "Traditional cuisine"}
INTERNATIONAL = {Language.DE: "Internationale Küche", Language.EN: "International cuisine"}
SPECIAL = {Language.DE: "Special", Language.EN: "Special"}

def to_json_obj(self):
return {
"name": self.name,
"text": json_util.dict_to_json_dict(self.text),
}

def to_api_representation(self) -> Dict[str, object]:
return {
"enum_name": self.name,
"text": json_util.dict_to_json_dict(self.text),
}


class Dish:
name: str
prices: Prices
labels: Set[Label]
dish_type: str
dish_type: DishType

def __init__(
self,
name: str,
prices: Prices,
labels: Set[Label],
dish_type: str,
dish_type: DishType,
):
self.name = name
self.prices = prices
Expand All @@ -564,11 +617,11 @@ def to_json_obj(self):
"name": self.name,
"prices": self.prices.to_json_obj(),
"labels": sorted(map(lambda l: l.name, self.labels)),
"dish_type": self.dish_type,
"dish_type": self.dish_type.to_json_obj(),
}

def __hash__(self) -> int:
# http://stackoverflow.com/questions/4005318/how-to-implement-a-good-hash-function-in-python
# https://stackoverflow.com/questions/4005318/how-to-implement-a-good-hash-function-in-python
return (hash(self.name) << 1) ^ hash(self.prices) ^ hash(frozenset(self.labels)) ^ hash(self.dish_type)


Expand Down
7 changes: 6 additions & 1 deletion src/enum_json_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def write_enum_as_api_representation_to_file(base_dir: str, filename: str, enum_
base_directory = sys.argv[1]
if not os.path.exists(base_directory):
raise FileNotFoundError(f"There is no such directory '{base_directory}'.")
enum_types = {entities.Canteen: "canteens.json", entities.Label: "labels.json", entities.Language: "languages.json"}
enum_types = {
entities.Canteen: "canteens.json",
entities.Label: "labels.json",
entities.Language: "languages.json",
entities.DishType: "dish_types.json",
}
for key, value in enum_types.items():
write_enum_as_api_representation_to_file(base_directory, value, key)
Loading
Loading