Refactoring
This commit is contained in:
@@ -1,24 +1,22 @@
|
||||
import os
|
||||
import magic
|
||||
from pathlib import Path
|
||||
from htmlmin import minify
|
||||
from time import time
|
||||
from datetime import datetime, timedelta
|
||||
from hashlib import md5
|
||||
from json import dumps
|
||||
from musicbrainzngs import get_image_front
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
|
||||
from flask import (
|
||||
Blueprint,
|
||||
request,
|
||||
render_template,
|
||||
send_file,
|
||||
send_from_directory,
|
||||
make_response,
|
||||
abort,
|
||||
make_response,
|
||||
render_template,
|
||||
request,
|
||||
send_file,
|
||||
)
|
||||
import magic
|
||||
from htmlmin import minify
|
||||
from musicbrainzngs import get_image_front
|
||||
|
||||
from .modules.api.lb import listens, listening
|
||||
from .modules.api.steam import recent, owned
|
||||
from .modules.api.lb import data as lb_data
|
||||
from .modules.api.steam import data as steam_data
|
||||
|
||||
def tmsmp(sec: int) -> str:
|
||||
if sec == 0:
|
||||
@@ -43,12 +41,6 @@ def utmsmp(unix: int) -> str:
|
||||
def rtmsmp(unix: int) -> str:
|
||||
return tmsmp(int(time() - unix))
|
||||
|
||||
def lb_etag():
|
||||
return md5((dumps(listens.get('data')) + dumps(listening.get('data'))).encode()).hexdigest()
|
||||
|
||||
def steam_etag():
|
||||
return md5((dumps(recent.get('data')) + dumps(owned.get('data'))).encode()).hexdigest()
|
||||
|
||||
bp = Blueprint(
|
||||
"risdeveau",
|
||||
__name__,
|
||||
@@ -82,12 +74,8 @@ def mb_cover(mbid):
|
||||
return r
|
||||
|
||||
args = {
|
||||
"lb_etag": lb_etag,
|
||||
"steam_etag": steam_etag,
|
||||
"lb": listens,
|
||||
"lb_now": listening,
|
||||
"recent": recent,
|
||||
"owned": owned,
|
||||
"lb": lb_data,
|
||||
"steam": steam_data,
|
||||
"tmsmp": tmsmp,
|
||||
"utmsmp": utmsmp,
|
||||
"rtmsmp": rtmsmp
|
||||
@@ -106,15 +94,15 @@ def module(module):
|
||||
if any((modified_since, none_match)):
|
||||
match module:
|
||||
case "listenbrainz":
|
||||
if modified_since >= int(max((x.get('last_updated', 0) for x in (listens, listening)))):
|
||||
if modified_since >= int(lb_data['last_updated']):
|
||||
return '', 304
|
||||
if none_match == lb_etag():
|
||||
if none_match == lb_data['etag']:
|
||||
return '', 304
|
||||
|
||||
case "steam":
|
||||
if modified_since >= int(max((x.get('last_updated', 0) for x in (recent, owned)))):
|
||||
return "Not updated yet", 304
|
||||
if none_match == steam_etag():
|
||||
if modified_since >= int(steam_data['last_updated']):
|
||||
return '', 304
|
||||
if none_match == steam_data['etag']:
|
||||
return '', 304
|
||||
|
||||
return render_tmpl(f'{module}.htm', **args)
|
||||
|
||||
Reference in New Issue
Block a user