change project structure

This commit is contained in:
vincent 2019-04-29 16:23:24 +02:00
parent d85afa8b49
commit 4d5290c8ed
6 changed files with 61 additions and 52 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
__*
__pycache__
env
venv
dist

0
backend/__init__.py Normal file
View File

35
backend/api.py Normal file
View File

@ -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/<num>', 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/<num>/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))

19
backend/app.py Normal file
View File

@ -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('/<path:path>')
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)

3
backend/config.py Normal file
View File

@ -0,0 +1,3 @@
class BaseConfig(object):
DEBUG = True
SECRET_KEY = 'mysecretkeyg'

View File

@ -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('/<path:path>')
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/<num>', 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/<num>/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)
from app import create_app
app= create_app()
app.run()