chainetv_web/backend/chainetv/api.py

35 lines
1.0 KiB
Python
Raw Normal View History

2019-04-29 14:23:24 +00:00
from flask import Blueprint, jsonify, request,make_response,redirect,url_for,render_template
2019-04-29 14:36:29 +00:00
from chainetv.Jsonfile import JSONfile
from chainetv import emission
2019-04-29 14:23:24 +00:00
data= JSONfile("chaine.json")
2019-04-29 14:36:29 +00:00
api = Blueprint("api", __name__)
2019-04-29 14:23:24 +00:00
@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))