chainetv_web/backend/api.py
2019-04-29 16:23:24 +02:00

36 lines
1013 B
Python

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))