forked from MarseyWorld/MarseyWorld
master
parent
c60adf958a
commit
c2815804c9
|
@ -34,6 +34,7 @@ def logged_out(old = ""):
|
|||
|
||||
return redirect(redirect_url)
|
||||
|
||||
|
||||
@app.get("/privacy")
|
||||
@auth_required
|
||||
def privacy(v):
|
||||
|
@ -133,8 +134,23 @@ def chart(v):
|
|||
return f
|
||||
|
||||
|
||||
@app.get("/weekly_chart")
|
||||
@auth_required
|
||||
def weekly_chart(v):
|
||||
file = cached_chart(kind="weekly")
|
||||
f = send_file(file)
|
||||
return f
|
||||
|
||||
@app.get("/daily_chart")
|
||||
@auth_required
|
||||
def daily_chart(v):
|
||||
file = cached_chart(kind="daily")
|
||||
f = send_file(file)
|
||||
return f
|
||||
|
||||
|
||||
@cache.memoize(timeout=86400)
|
||||
def cached_chart(days):
|
||||
def cached_chart(kind):
|
||||
now = time.gmtime()
|
||||
midnight_this_morning = time.struct_time((now.tm_year,
|
||||
now.tm_mon,
|
||||
|
@ -148,11 +164,11 @@ def cached_chart(days):
|
|||
)
|
||||
today_cutoff = calendar.timegm(midnight_this_morning)
|
||||
|
||||
if days:
|
||||
file = "daily_chart.png"
|
||||
if kind == "daily":
|
||||
file = "/daily_chart.png"
|
||||
day_cutoffs = [today_cutoff - 86400 * i for i in range(47)][1:]
|
||||
else:
|
||||
file = "weekly_chart.png"
|
||||
file = "/weekly_chart.png"
|
||||
day_cutoffs = [today_cutoff - 86400 * 7 * i for i in range(47)][1:]
|
||||
|
||||
day_cutoffs.insert(0, calendar.timegm(now))
|
||||
|
|
Loading…
Reference in New Issue