initial
This commit is contained in:
commit
55778039fb
5 files changed
+164
No files matched your search
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
Try to input dishes from the coming week.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
import subprocess
|
||||
from datetime import date, timedelta
|
||||
|
||||
DB = "mensa.db"
|
||||
MENSEN = ["cgin", "mensa_am_turm", "zentralmensa"]
|
||||
|
||||
db = sqlite3.connect(DB)
|
||||
|
||||
db.execute("""
|
||||
CREATE TABLE IF NOT EXISTS dishes (
|
||||
date TEXT NOT NULL,
|
||||
mensa TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
title TEXT,
|
||||
description TEXT,
|
||||
category TEXT,
|
||||
allergens TEXT,
|
||||
UNIQUE(date, mensa, type)
|
||||
)
|
||||
""")
|
||||
|
||||
TODAY = date.today()
|
||||
|
||||
for i in range(7):
|
||||
day = TODAY + timedelta(days=i)
|
||||
|
||||
for mensa in MENSEN:
|
||||
result = subprocess.run(
|
||||
["python", "mensa.py", day.isoformat(), mensa],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
if not result.stdout:
|
||||
print(f"no results: {day} {mensa}")
|
||||
continue
|
||||
|
||||
dishes = json.loads(result.stdout)
|
||||
|
||||
for dish in dishes:
|
||||
try:
|
||||
db.execute(
|
||||
"""
|
||||
INSERT INTO dishes
|
||||
(date, mensa, type, title, description, category, allergens)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
dish["date"],
|
||||
dish["mensa"],
|
||||
dish["type"],
|
||||
dish["title"],
|
||||
dish["description"],
|
||||
json.dumps(dish["category"], ensure_ascii=False),
|
||||
json.dumps(dish["allergens"], ensure_ascii=False),
|
||||
),
|
||||
)
|
||||
print(f"registered: {dish['date']} {dish['mensa']} {dish['type']}")
|
||||
except sqlite3.IntegrityError:
|
||||
print(
|
||||
f"already registered: {dish['date']} {dish['mensa']} {dish['type']}"
|
||||
)
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
Reference in new issue
Block a user