Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
feat: show day after tomorrow's menu in notion (#6)
Browse files Browse the repository at this point in the history
* feat: show day after tomorrow's meals in notion

* fix: predefined 3 notion blocks

* chore: version bump
  • Loading branch information
sralloza authored Oct 13, 2021
1 parent 259afca commit be91c6f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/cron/update_notion_meals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ def update_notion_meals():
with manual_db() as db:
today_meal = crud.meal.get_today(db)
tomorrow_meal = crud.meal.get_tomorrow(db)
dat_meal = crud.meal.get_day_after_tomorrow(db)

today_meal = Meal.from_orm(today_meal) if today_meal else None
tomorrow_meal = Meal.from_orm(tomorrow_meal) if tomorrow_meal else None
dat_meal = Meal.from_orm(dat_meal) if dat_meal else None

blocks = []
blocks.append(create_notion_block("Hoy\n", bold=True))
Expand All @@ -24,7 +26,11 @@ def update_notion_meals():
if tomorrow_meal:
blocks.extend(tomorrow_meal.to_notion_blocks())

if len(blocks) <= 2:
blocks.append(create_notion_block("\nPasado mañana\n", bold=True))
if dat_meal:
blocks.extend(dat_meal.to_notion_blocks())

if len(blocks) <= 3:
print("warning: not blocks detected in cron-script update-notion-meals")
return

Expand Down
3 changes: 3 additions & 0 deletions app/crud/crud_meal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def get_today(self, db: Session):
def get_tomorrow(self, db: Session):
return self.get_by_date_delta(db, delta_days=1)

def get_day_after_tomorrow(self, db: Session):
return self.get_by_date_delta(db, delta_days=2)

def get_week(self, db: Session, *, week: int):
return db.query(self.model).filter(func.weekofyear(self.model.id) == week).all()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "meal-planner"
version = "1.0.1"
version = "1.1.0"
description = ""
authors = ["Diego Alloza González <[email protected]>"]
packages = [
Expand Down

0 comments on commit be91c6f

Please sign in to comment.