mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-31 12:56:11 +01:00
Add ability to load credits from remote
This commit is contained in:
parent
3dbbc69753
commit
1596c720cb
@ -264,12 +264,24 @@ class PanelHandler(BaseHandler):
|
||||
template = "public/error.html"
|
||||
|
||||
elif page == 'credits':
|
||||
with open(helper.credits_cache, encoding='utf-8') as republic_credits_will_do:
|
||||
credits_dict: dict = json.load(republic_credits_will_do)
|
||||
with open(helper.credits_cache, encoding='utf-8') as credits_default_local:
|
||||
try:
|
||||
remote = requests.get('https://craftycontrol.com/credits', allow_redirects=True)
|
||||
credits_dict: dict = remote.json()
|
||||
if not credits_dict["staff"]:
|
||||
logger.error("Issue with upstream Staff, using local.")
|
||||
credits_dict: dict = json.load(credits_default_local)
|
||||
except:
|
||||
logger.error("Request to credits bucket failed, using local.")
|
||||
credits_dict: dict = json.load(credits_default_local)
|
||||
|
||||
timestamp = credits_dict["lastUpdate"] / 1000.0
|
||||
page_data["patrons"] = credits_dict["patrons"]
|
||||
page_data["staff"] = credits_dict["staff"]
|
||||
page_data["translations"] = credits_dict["translations"]
|
||||
if timestamp == 0:
|
||||
page_data["lastUpdate"] = '😿'
|
||||
else:
|
||||
page_data["lastUpdate"] = str(datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'))
|
||||
template = "panel/credits.html"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user