bcns-gameDistributionSystem/site/modules/gamelist.py
odecif 909e01c373 Gamelist in memory
Instead of always scanning the game folder for nfo's when presenting the
gamelist it is now loaded once into memory and then accessed from there.
2022-10-28 11:04:27 +02:00

39 lines
1.1 KiB
Python

from __main__ import app
import json
import requests
from flask import render_template, redirect, url_for
import modules.init
host_endpoint = modules.init.host_endpoint()
languages = modules.init.get_languages()
app_language = modules.init.app_language
# Check if valid language code is set. If not, return app default
def lang(lang_code):
if lang_code not in languages:
return app_language
return lang_code
# Show gamelist
@app.route("/<lang_code>/gamelist")
# @app.route("/gamelist")
def gamelist(lang_code):
lang_code = lang(lang_code)
glist = json.loads((requests.get(
host_endpoint + '/gamelist').content).decode())
return render_template('gamelist.html', gamelist=glist,
**languages[lang_code], lang_code=lang_code)
# Update/Refresh the gamelist by re-scanning the game archive (slow)
@app.route("/<lang_code>/gamelist/update")
def gamelist_update(lang_code):
lang_code = lang(lang_code)
response = requests.get(
host_endpoint + '/gamelist/update')
if response.status_code == 200:
return redirect(url_for('gamelist', lang_code=lang_code))