Skip to content

Commit

Permalink
Merge pull request #54 from ScilifelabDataCentre/rafven-parser
Browse files Browse the repository at this point in the history
Add parser for Svarta Räfven
  • Loading branch information
talavis authored Jan 18, 2023
2 parents c5d9407 + 5169b89 commit 0e5e745
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions backend/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def restaurant(func):
"""

def helper(res_data):
map_url = ("https://www.openstreetmap.org/#map=19/"
f"{res_data['coordinate'][0]}/{res_data['coordinate'][1]}")
map_url = (
"https://www.openstreetmap.org/#map=19/"
f"{res_data['coordinate'][0]}/{res_data['coordinate'][1]}"
)
data = {
"title": res_data["name"],
"location": res_data["region"],
Expand Down Expand Up @@ -397,9 +399,7 @@ def parse_maethai(res_data):

@restaurant
def parse_nanna(res_data):
"""
Parse the menu of Nanna Svartz.
"""
"""Parse the menu of Nanna Svartz."""
data = {"menu": []}
soup = get_parser(res_data["menuUrl"])

Expand Down Expand Up @@ -476,7 +476,29 @@ def parse_street(res_data):

@restaurant
def parse_svarta(res_data):
"""
Parse the menu of Svarta Räfven
"""
return {"menu": []}
"""Parse the menu of Svarta Räfven."""
data = {"menu": []}
soup = get_parser(res_data["menuUrl"])

weeks = soup.find_all("div", {"class": "menu-container"})
for week in weeks:
try:
header = week.find("h2", {"class": "section-title"}).text
except AttributeError:
continue
if f"Lunch vecka {get_week()}" in header:
entries = week.find_all("div", {"class": "menu-item"})
for entry in entries:
dish = ""
for row in entry.find_all("p"):
p_class = row.get("class")
if p_class:
if "menu-en" in p_class:
continue
if "small-title" in p_class:
dish += row.text.strip() + ": "
else:
dish += row.text.strip()
data["menu"].append(dish)

return data

0 comments on commit 0e5e745

Please sign in to comment.