gf
This commit is contained in:
parent
5c22289b1e
commit
2b62d395b5
1 changed files with 31 additions and 15 deletions
|
@ -34,6 +34,7 @@ def logged_out(old = ""):
|
||||||
|
|
||||||
return redirect(redirect_url)
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/privacy")
|
@app.get("/privacy")
|
||||||
@auth_required
|
@auth_required
|
||||||
def privacy(v):
|
def privacy(v):
|
||||||
|
@ -133,8 +134,23 @@ def chart(v):
|
||||||
return f
|
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)
|
@cache.memoize(timeout=86400)
|
||||||
def cached_chart(days):
|
def cached_chart(kind):
|
||||||
now = time.gmtime()
|
now = time.gmtime()
|
||||||
midnight_this_morning = time.struct_time((now.tm_year,
|
midnight_this_morning = time.struct_time((now.tm_year,
|
||||||
now.tm_mon,
|
now.tm_mon,
|
||||||
|
@ -148,11 +164,11 @@ def cached_chart(days):
|
||||||
)
|
)
|
||||||
today_cutoff = calendar.timegm(midnight_this_morning)
|
today_cutoff = calendar.timegm(midnight_this_morning)
|
||||||
|
|
||||||
if days:
|
if kind == "daily":
|
||||||
file = "daily_chart.png"
|
file = "/daily_chart.png"
|
||||||
day_cutoffs = [today_cutoff - 86400 * i for i in range(47)][1:]
|
day_cutoffs = [today_cutoff - 86400 * i for i in range(47)][1:]
|
||||||
else:
|
else:
|
||||||
file = "weekly_chart.png"
|
file = "/weekly_chart.png"
|
||||||
day_cutoffs = [today_cutoff - 86400 * 7 * i for i in range(47)][1:]
|
day_cutoffs = [today_cutoff - 86400 * 7 * i for i in range(47)][1:]
|
||||||
|
|
||||||
day_cutoffs.insert(0, calendar.timegm(now))
|
day_cutoffs.insert(0, calendar.timegm(now))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue