bcns-gameDistributionSystem/api/api.py
odecif ad3fd6a195 JSONEncoder and manual
Focus on remving deprecated flas.JSONEncoder and replacing it with
json.JSONEncoder.

* Exception handling when API is not accessible [fix #25]
* flask.JSONEncoder deprecated [fix #24]
* Show manual (if present) [fix #23]
* Small touch-ups
2023-09-19 00:47:31 +02:00

49 lines
1.1 KiB
Python

from flask import request, jsonify, Flask
import json
from datetime import date
import modules.db_connect
class MyJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, date):
return o.isoformat()
return super().default(o)
class MyFlask(Flask):
json_encoder = MyJSONEncoder
app = MyFlask(__name__)
modules.db_connect.init()
import modules.gamelist # noqa: E402
import modules.game # noqa: E402
# Important initialization stuff
config = modules.db_connect.config
# 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")
# Fetch a list of one users owned vehicles
@app.route('/<userid>/vehiclelist', methods=['GET'])
def user_vehiclelist(userid):
return False
if __name__ == '__main__':
app.config['JSON_AS_ASCII'] = False
app.run(
host=config.get('Running', 'host'),
port=config.get('Running', 'Port'))