Skip to content

Commit

Permalink
Fix salad bowls
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Oct 3, 2023
1 parent b4418f7 commit ab0ab46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions server/scraper/resto/sandwiches.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sys
sys.path.append('..')

from util import parse_money, write_json_to_file
from util import parse_money, write_json_to_file, split_price

SANDWICHES_URL = "https://www.ugent.be/student/nl/meer-dan-studeren/resto/broodjes/overzicht.htm"
HTML_PARSER = 'lxml'
Expand Down Expand Up @@ -116,8 +116,7 @@ def weekly_sandwiches(output, soup):
'start': start,
'end': end,
'name': columns[1].text.strip(),
'ingredients': parse_ingredients(columns[2].text),
'vegan': 'x' in columns[3].text
'ingredients': parse_ingredients(columns[2].text)
})

today = datetime.date.today()
Expand Down Expand Up @@ -166,15 +165,17 @@ def salad_bowls(output, soup):
"""
bowls = []

tables = soup.find_all('table', limit=3)
tables = soup.find_all('table', limit=4)

if len(tables) >= 3:
for row in soup.find_all('table', limit=3)[2].find_all("tr", class_=lambda x: x != 'tabelheader'):
if len(tables) >= 4:
header = soup.find('a', id="salad-bowls").parent
_, price = split_price(header.text) if header else (None, None)
for row in tables[3].find_all("tr", class_=lambda x: x != 'tabelheader'):
columns = row.find_all("td")
bowls.append({
'name': columns[0].text.strip(),
'description': columns[1].text.strip(),
'price': parse_money(columns[2].string) if columns[2].string else ""
'price': parse_money(price) if price else ""
})

output_file = os.path.join(output, SALADS)
Expand Down
2 changes: 1 addition & 1 deletion server/scraper/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def split_price(meal):
return name, price
elif "€" in meal:
meal, price = meal.split("€")
return meal.strip(), price
return meal.strip(), price.strip()
else:
return meal.strip(), ""

Expand Down

0 comments on commit ab0ab46

Please sign in to comment.