bcns-gameDistributionSystem/bcnsGDSAPI/__init__.py
odecif aac63b7eb3 Changed config handler
Added printout when instance folder is not found.
2023-11-21 13:02:45 +01:00

55 lines
1.5 KiB
Python

from flask import request, jsonify, Flask
import json
from datetime import date
import tomllib
import os
class MyJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, date):
return o.isoformat()
return super().default(o)
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config['JSON_AS_ASCII'] = False
if test_config is None:
app.config.from_file('bcnsgdsapi-config.toml',
load=tomllib.load, text=False)
else:
app.config.from_mapping(test_config)
try:
os.makedirs(app.instance_path, exist_ok=True)
except OSError:
print(
"Error: instance path not found!" +
" No configuration file has been loaded")
pass
import bcnsGDSAPI.modules.db_connect
bcnsGDSAPI.modules.db_connect.init(app.config)
from bcnsGDSAPI.modules.gamelist import gamelist
from bcnsGDSAPI.modules.game import game
app.register_blueprint(gamelist)
app.register_blueprint(game)
# Just a simple homepage, nothing fancy
@app.route('/', methods=['GET'])
def home():
if 'id' not in request.args:
return "<h1>BCNS Game Distribution System</h1><p>API-endpoint</p>"
else:
return jsonify("I see you're a man of culture as well")
return app
if __name__ == "__main__":
app = create_app()
app.run(host="0.0.0.0", port=8001, debug=True)