From 4d5290c8ed8a2721d519a6b92dc7090661973a33 Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 29 Apr 2019 16:23:24 +0200 Subject: [PATCH] change project structure --- .gitignore | 2 +- backend/__init__.py | 0 backend/api.py | 35 +++++++++++++++++++++++++++++ backend/app.py | 19 ++++++++++++++++ backend/config.py | 3 +++ backend/run.py | 54 +++------------------------------------------ 6 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 backend/__init__.py create mode 100644 backend/api.py create mode 100644 backend/app.py create mode 100644 backend/config.py 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