make /live a cached cron job

master
Aevann1 2022-09-22 04:33:45 +02:00
parent 59f7a7655b
commit 553218aaa5
2 changed files with 13 additions and 5 deletions

View File

@ -39,6 +39,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo):
stats.generate_charts_task(SITE) stats.generate_charts_task(SITE)
route_static.stats_cached() route_static.stats_cached()
sub_inactive_purge_task() sub_inactive_purge_task()
if SITE_NAME == 'PCM':
route_static.live_cached()
if every_1mo: if every_1mo:
if KOFI_LINK: give_monthly_marseybux_task_kofi() if KOFI_LINK: give_monthly_marseybux_task_kofi()

View File

@ -466,10 +466,8 @@ if SITE_NAME == 'PCM':
live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A) live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A)
offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"url":"(.*?)"', flags=re.A) offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"url":"(.*?)"', flags=re.A)
@app.get('/live') @cache.memoize(timeout=86400)
@app.get('/logged_out/live') def live_cached():
@auth_desired_with_logingate
def live(v):
live = [] live = []
offline = [] offline = []
for x in streamers: for x in streamers:
@ -489,4 +487,12 @@ if SITE_NAME == 'PCM':
try: offline.append((req.url, y.group(2), y.group(1))) try: offline.append((req.url, y.group(2), y.group(1)))
except: print(x) except: print(x)
return render_template(f'live.html', v=v, live=live, offline=offline) live = sorted(live, key=lambda x: x[4], reverse=True)
return live, offline
@app.get('/live')
@app.get('/logged_out/live')
@auth_desired_with_logingate
def live(v):
return render_template(f'live.html', v=v, live=live_cached()[0], offline=live_cached()[1])