bcns-gameDistributionSystem/bcnsGDSAPI/modules/gamelist.py
odecif 77b0bcb94a Prepare API for gunicorn
It is now possible to run the API with gunicorn using
gunicorn -w 4 -b 0.0.0.0:8001 'bcnsGDSAPI:create_app()'.

Also did other small changes.
2023-11-21 12:51:35 +01:00

57 lines
1.7 KiB
Python

from flask import jsonify, make_response, Blueprint
import bcnsGDSAPI.modules.db_connect
from bcnsGDSAPI.modules.functions import get_gamelist, set_gamelist
import bcnsGDSAPI.modules.game
from bcnsGDSAPI.modules.gamelist_functions import (
get_threaded_thumbnails,
update_threaded_thumbnails)
import glob
contentpath = bcnsGDSAPI.modules.db_connect.contentpath()
nfosuffix = bcnsGDSAPI.modules.db_connect.nfosuffix()
gamelist = Blueprint('gamelist', __name__, template_folder='templates')
# Collects all _index.nfo-files present and crunches them into a list of
# games.
@gamelist.route('/gamelist', methods=['GET'])
def show_gamelist():
if get_gamelist():
return jsonify(get_gamelist())
update_gamelist()
return jsonify(get_gamelist())
# Updates the gamelist by searching for new nfo's
@gamelist.route('/gamelist/update', methods=['GET'])
def update_gamelist():
nfolist = list(dict.fromkeys(glob.glob(
str(contentpath)+'/**/**/*'+nfosuffix, recursive=True)))
glist = []
for nfo in nfolist:
try:
game = bcnsGDSAPI.modules.game.showgame(nfo, True, True, True)
glist.append(game)
except Exception as e:
print(nfo, e)
set_gamelist(glist)
return make_response("<h1>Success</h1>", 200)
# Fetch displayimage for all nfo-files
@gamelist.route('/gamelist/displayimage')
def get_displayimages(update=False):
thumbnails = get_threaded_thumbnails()
if (len(thumbnails) == 0) or update:
thumbnails = update_threaded_thumbnails(True)
return jsonify(thumbnails)
# Update displayimages
@gamelist.route('/gamelist/displayimage/update')
def update_displayimages():
update_threaded_thumbnails()
return make_response("<h1>Success</h1>", 200)