Skip to content

Commit

Permalink
Merge pull request #86 from filips123/xlsx-parsing
Browse files Browse the repository at this point in the history
Xlsx parsing
  • Loading branch information
PetJer authored Sep 24, 2023
2 parents 3be64c5 + 1cf8731 commit e583ee9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions API/gimvicurnik/updaters/eclassroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,6 @@ def _parse_lunch_schedule_xlsx(self, stream: BytesIO, effective: date) -> None:

# Parse lunch schedule
for ws in wb:
if ws.title != "kosilo":
continue

for wr in ws.iter_rows(min_row=3, max_col=5):
if not wr[0].value:
break
Expand All @@ -768,24 +765,25 @@ def _parse_lunch_schedule_xlsx(self, stream: BytesIO, effective: date) -> None:
assert isinstance(wr[2].value, str)
assert isinstance(wr[4].value, str)

if "prilagoditev" in wr[1].value:
continue

schedule: dict[str, Any] = {}

# Time in format H:M
schedule["time"] = wr[0].value

# Notes
schedule["notes"] = wr[1].value.strip() if wr[1].value else None

# Class name (class id)
if wr[2].value:
schedule["class_id"] = get_or_create(self.session, model=Class, name=wr[2].value.strip())[
0
].id
# fmt: off
schedule["class_id"] = get_or_create(
self.session, model=Class, name=wr[2].value.strip()
)[0].id
# fmt: on

# Location
schedule["location"] = wr[4].value.strip() if wr[4].value else None

# Effective date
schedule["date"] = effective
lunch_schedule.append(schedule)

Expand Down
4 changes: 2 additions & 2 deletions API/gimvicurnik/updaters/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def _parse_snack_menu_xlsx(self, stream: BytesIO, effective: datetime.date) -> N
snack_menu["fruitvegetable"].append(wr[4].value.strip())

# Store the menu after the end of day
if wr[0].border.bottom.color:
if wr[1].border.bottom.color:
snack_menu["date"] = effective + datetime.timedelta(days=days)
self.session.query(SnackMenu).filter(SnackMenu.date == snack_menu["date"]).delete()

Expand Down Expand Up @@ -312,7 +312,7 @@ def _parse_lunch_menu_xlsx(self, stream: BytesIO, effective: datetime.date) -> N
lunch_menu["vegetarian"].append(wr[2].value.strip())

# Store the menu after the end of day
if wr[0].border.bottom.color:
if wr[1].border.bottom.color:
lunch_menu["date"] = effective + datetime.timedelta(days=days)
self.session.query(LunchMenu).filter(LunchMenu.date == lunch_menu["date"]).delete()

Expand Down

0 comments on commit e583ee9

Please sign in to comment.