async test
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import json
|
||||
from init import db, Meals, scheduler
|
||||
from init import db, Meals#, scheduler
|
||||
import datetime
|
||||
import requests
|
||||
import time
|
||||
@ -110,29 +110,29 @@ def formatDay(day: datetime):
|
||||
return day
|
||||
|
||||
|
||||
@scheduler.task('cron', id="refreshMeals", hour='8-11', day_of_week='*', minute='15', week='*', second='30')
|
||||
#@scheduler.task('cron', id="refreshMeals", hour='8-11', day_of_week='*', minute='15', week='*', second='30')
|
||||
def refreshMeals():
|
||||
"""
|
||||
Aktualisiert immer vormittags alle Mahlzeiten in der Datenbank. \n
|
||||
Datenbankeinträge werden ersetzt, wenn die API andere Mahlzeiten liefert.
|
||||
"""
|
||||
print("Aktualisiere Essenspläne...\n")
|
||||
with scheduler.app.app_context():
|
||||
table = Meals.query.all()
|
||||
dates = []
|
||||
for i in table:
|
||||
if i.date not in dates:
|
||||
dates += [i.date]
|
||||
for i in range(len(dates)):
|
||||
dates[i] = formatDay(dates[i])
|
||||
for i in dates:
|
||||
apinames = getMealsFromAPI(i)
|
||||
dbmeals = Meals.query.filter_by(date=i).all()
|
||||
dbnames = []
|
||||
for m in dbmeals:
|
||||
dbnames += [m.name]
|
||||
if set(dbnames) != set(apinames) and nomeal not in apinames:
|
||||
for n in dbnames:
|
||||
db.session.delete(Meals.query.filter_by(date=i, name=n).first())
|
||||
db.session.commit()
|
||||
getMealsFromAPI(i, True)
|
||||
#with scheduler.app.app_context():
|
||||
# table = Meals.query.all()
|
||||
# dates = []
|
||||
# for i in table:
|
||||
# if i.date not in dates:
|
||||
# dates += [i.date]
|
||||
# for i in range(len(dates)):
|
||||
# dates[i] = formatDay(dates[i])
|
||||
# for i in dates:
|
||||
# apinames = getMealsFromAPI(i)
|
||||
# dbmeals = Meals.query.filter_by(date=i).all()
|
||||
# dbnames = []
|
||||
# for m in dbmeals:
|
||||
# dbnames += [m.name]
|
||||
# if set(dbnames) != set(apinames) and nomeal not in apinames:
|
||||
# for n in dbnames:
|
||||
# db.session.delete(Meals.query.filter_by(date=i, name=n).first())
|
||||
# db.session.commit()
|
||||
# getMealsFromAPI(i, True)
|
||||
|
||||
Reference in New Issue
Block a user