more linting and availability added.
This commit is contained in:
@@ -20,6 +20,11 @@ class SWPWebspeiseplanAPI:
|
||||
logging.basicConfig()
|
||||
proxy_token = self.parse_token()
|
||||
self.outlets = self.parse_outlets(proxy_token)
|
||||
self.locations: dict[str, dict] = {}
|
||||
locations = {
|
||||
item["id"]: item
|
||||
for item in self.parse_location(proxy_token)
|
||||
}
|
||||
self.menus: dict[str, dict] = {}
|
||||
self.meal_categories: dict[str, dict] = {}
|
||||
for outlet in self.outlets.values():
|
||||
@@ -29,6 +34,7 @@ class SWPWebspeiseplanAPI:
|
||||
id2cat = {item["gerichtkategorieID"]: item for item in categories}
|
||||
self.menus[outlet["name"]] = menu
|
||||
self.meal_categories[outlet["name"]] = id2cat
|
||||
self.locations[outlet["name"]] = locations[location]
|
||||
|
||||
def __spoof_req_headers(self, req: urllib.request.Request):
|
||||
"""Add headers to a request .
|
||||
@@ -139,3 +145,15 @@ class SWPWebspeiseplanAPI:
|
||||
}
|
||||
menu = self.parse_model(params)
|
||||
return menu
|
||||
|
||||
def parse_location(self, proxy_token: str) -> list[dict]:
|
||||
"""Get the meal catrgories for a specific location."""
|
||||
params = {
|
||||
"token": proxy_token,
|
||||
"model": "location",
|
||||
"location": "",
|
||||
"languagetype": 1,
|
||||
"_": int(time.time() * 1000),
|
||||
}
|
||||
menu = self.parse_model(params)
|
||||
return menu
|
||||
|
||||
@@ -28,6 +28,7 @@ class SWPWebspeiseplanParser:
|
||||
"city": addr_info["city"],
|
||||
"phone": outlet["contactInfo"][0]["phone"],
|
||||
"email": outlet["contactInfo"][0]["email"],
|
||||
"availability": outlet["isPublic"]
|
||||
}
|
||||
|
||||
if outlet["positionInfo"]:
|
||||
@@ -36,7 +37,6 @@ class SWPWebspeiseplanParser:
|
||||
outlet["positionInfo"]["latitude"],
|
||||
)
|
||||
canteen_meta = CanteenMeta(**meta)
|
||||
# TODO: availability via locations isPublic
|
||||
weekday_dict = {
|
||||
"monday": f"{outlet['moZeit1']}, {outlet['moZeit2']}",
|
||||
"tuesday": f"{outlet['diZeit1']}, {outlet['diZeit2']}",
|
||||
|
||||
@@ -29,6 +29,8 @@ class Builder:
|
||||
outlet = swp_api.outlets[ntup.name]
|
||||
menus = swp_api.menus[ntup.name]
|
||||
categories = swp_api.meal_categories[ntup.name]
|
||||
locations = swp_api.locations[ntup.name]
|
||||
outlet["isPublic"] = locations["isPublic"]
|
||||
canteen = swp_parser.parse_canteen_meta_times(outlet)
|
||||
meals = swp_parser.parse_meals(menus, categories)
|
||||
for kwargs in meals:
|
||||
|
||||
@@ -32,7 +32,11 @@ class CanteenMeta:
|
||||
|
||||
@availability.setter
|
||||
def availability(self, value: str):
|
||||
if value in ("public", "restricted"):
|
||||
if value is True:
|
||||
self._availability = "public"
|
||||
elif value is False:
|
||||
self._availability = "restricted"
|
||||
elif value in ("public", "restricted"):
|
||||
self._availability = value
|
||||
else:
|
||||
raise ValueError("only 'public' or 'restricted' are allowed.")
|
||||
@@ -89,8 +93,12 @@ class CanteenXML:
|
||||
canteen.appendChild(email)
|
||||
if self.canteen_meta.location:
|
||||
location = doc.createElement("location")
|
||||
location.setAttribute("longitude", str(self.canteen_meta.location[0]))
|
||||
location.setAttribute("latitude", str(self.canteen_meta.location[1]))
|
||||
location.setAttribute(
|
||||
"longitude", str(self.canteen_meta.location[0])
|
||||
)
|
||||
location.setAttribute(
|
||||
"latitude", str(self.canteen_meta.location[1])
|
||||
)
|
||||
canteen.appendChild(location)
|
||||
availability = self.__create_node(
|
||||
doc, "availability", self.canteen_meta.availability
|
||||
|
||||
Reference in New Issue
Block a user