diff --git a/.gitignore b/.gitignore index ac77d92..947795f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -__* +__pycache__ env venv dist \ No newline at end of file diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/api.py b/backend/api.py new file mode 100644 index 0000000..2fae157 --- /dev/null +++ b/backend/api.py @@ -0,0 +1,35 @@ +from flask import Blueprint, jsonify, request,make_response,redirect,url_for,render_template +from Jsonfile import JSONfile +import emission +data= JSONfile("chaine.json") +api = Blueprint("api", __name__) + + + +@api.route('/ping', methods=['GET']) +def ping_pong(): + return jsonify('pong!') + +@api.route('/chaine/', methods=['GET']) +def get_chaine(num): + chaine=data.get_chaine(num) + if (chaine == "numero de chaine inconnue"): + return make_response("",204) + else: + return jsonify(chaine) + +@api.route('/chaine/', methods=['put']) +def update_list(): + status=data.parsechaine() + if(status=='ok'): + return jsonify("OK") + else: + return make_response('Error during Chaine Update',500) + +@api.route('/chaine//emission', methods=['GET']) +def get_emmission(num): + chaine=data.get_chaine(num) + if (chaine == "numero de chaine inconnue"): + return make_response("",204) + else: + return jsonify(emission.parse_emmission(chaine)) diff --git a/backend/app.py b/backend/app.py new file mode 100644 index 0000000..1a10cf0 --- /dev/null +++ b/backend/app.py @@ -0,0 +1,19 @@ +from flask import Flask,render_template +from flask_cors import CORS +from api import api +#from ReverseProxied import ReverseProxied +def create_app(app_name=__name__): + app=Flask(__name__, static_folder= "./dist/static",template_folder="./dist") + app.config.from_object('config.BaseConfig') + #app.wsgi_app = ReverseProxied(app.wsgi_app) + CORS(app) + app.register_blueprint(api, url_prefix="/api/v1") + @app.route('/') + def index(path): + return render_template('index.html') + return app + + +##@app.errorhandler(404) +##def ma_page_404(error): +## return redirect("https://www.ducamps.win/404/404.html", 307) diff --git a/backend/config.py b/backend/config.py new file mode 100644 index 0000000..24dea4c --- /dev/null +++ b/backend/config.py @@ -0,0 +1,3 @@ +class BaseConfig(object): + DEBUG = True + SECRET_KEY = 'mysecretkeyg' \ No newline at end of file diff --git a/backend/run.py b/backend/run.py index 8df6d4a..3b426ae 100644 --- a/backend/run.py +++ b/backend/run.py @@ -1,52 +1,4 @@ -from flask import Flask,request,make_response,redirect,url_for,render_template,jsonify -from flask_cors import CORS -from Jsonfile import JSONfile -#from ReverseProxied import ReverseProxied -import emission -data= JSONfile("chaine.json") -app=Flask(__name__,static_folder = "./dist/static",template_folder="./dist") -#app.wsgi_app = ReverseProxied(app.wsgi_app) -CORS(app) - -@app.route('/', defaults={'path': ''}) -@app.route('/') -def index(path): - return render_template('index.html') - -@app.route('/api/v1/ping', methods=['GET']) -def ping_pong(): - return jsonify('pong!') - -@app.route('/api/v1/chaine/', methods=['GET']) -def get_chaine(num): - chaine=data.get_chaine(num) - if (chaine == "numero de chaine inconnue"): - return make_response("",204) - else: - return jsonify(chaine) - -@app.route('/api/v1/chaine/', methods=['put']) -def update_list(): - status=data.parsechaine() - if(status=='ok'): - return jsonify("OK") - else: - return make_response('Error during Chaine Update',500) - -@app.route('/api/v1/chaine//emission', methods=['GET']) -def get_emmission(num): - chaine=data.get_chaine(num) - if (chaine == "numero de chaine inconnue"): - return make_response("",204) - else: - return jsonify(emission.parse_emmission(chaine)) - -##@app.errorhandler(404) -##def ma_page_404(error): -## return redirect("https://www.ducamps.win/404/404.html", 307) - - - - if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + from app import create_app + app= create_app() + app.run() \ No newline at end of file