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