chainetv_web/backend/run.py

52 lines
1.5 KiB
Python
Raw Normal View History

2019-04-24 11:57:08 +00:00
from flask import Flask,request,make_response,redirect,url_for,render_template,jsonify
from flask_cors import CORS
2019-04-25 08:30:48 +00:00
from Jsonfile import JSONfile
2019-04-26 08:21:58 +00:00
#from ReverseProxied import ReverseProxied
2019-04-25 15:27:49 +00:00
import emission
2019-04-25 08:30:48 +00:00
data= JSONfile("chaine.json")
2019-04-26 07:52:40 +00:00
app=Flask(__name__,static_folder = "./dist/static",template_folder="./dist")
2019-04-26 08:21:58 +00:00
#app.wsgi_app = ReverseProxied(app.wsgi_app)
2019-04-24 11:57:08 +00:00
CORS(app)
2019-04-26 07:52:40 +00:00
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
return render_template('index.html')
2019-04-24 11:57:08 +00:00
2019-04-25 15:52:32 +00:00
@app.route('/api/v1/ping', methods=['GET'])
2019-04-24 11:57:08 +00:00
def ping_pong():
return jsonify('pong!')
@app.route('/api/v1/chaine/<num>', methods=['GET'])
def get_chaine(num):
2019-04-25 18:26:49 +00:00
chaine=data.get_chaine(num)
if (chaine == "numero de chaine inconnue"):
return make_response("",204)
else:
return jsonify(chaine)
2019-04-24 11:57:08 +00:00
@app.route('/api/v1/chaine/', methods=['put'])
def update_list():
2019-04-25 18:26:49 +00:00
status=data.parsechaine()
2019-04-25 15:49:21 +00:00
if(status=='ok'):
return jsonify("OK")
else:
return make_response('Error during Chaine Update',500)
2019-04-25 15:27:49 +00:00
@app.route('/api/v1/chaine/<num>/emission', methods=['GET'])
def get_emmission(num):
chaine=data.get_chaine(num)
if (chaine == "numero de chaine inconnue"):
2019-04-25 18:26:49 +00:00
return make_response("",204)
2019-04-25 15:27:49 +00:00
else:
return jsonify(emission.parse_emmission(chaine))
2019-04-24 11:57:08 +00:00
##@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)