add emission parser to api
This commit is contained in:
parent
dee0dcb7fd
commit
98862ad0eb
47
backend/emission.py
Normal file
47
backend/emission.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import urllib.request
|
||||||
|
import re
|
||||||
|
|
||||||
|
#debug
|
||||||
|
#import pprint
|
||||||
|
|
||||||
|
def parse_emmission(strsearch):
|
||||||
|
URL="https://www.programme-tv.net/programme/canal-5/"
|
||||||
|
try:
|
||||||
|
response = urllib.request.urlopen(URL)
|
||||||
|
except urllib.error.URLError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
html = response.read()
|
||||||
|
parse=BeautifulSoup(html,"html.parser")
|
||||||
|
strsearch=strsearch.replace('É','E')
|
||||||
|
linkchaine=parse.find(text=re.compile(re.escape(strsearch)))
|
||||||
|
if linkchaine == None:
|
||||||
|
return "can't find channel"
|
||||||
|
link=linkchaine.parent.parent.find_next_sibling().find("a")
|
||||||
|
href=link['href']
|
||||||
|
response = urllib.request.urlopen(href)
|
||||||
|
html = response.read()
|
||||||
|
parse=BeautifulSoup(html,"html.parser")
|
||||||
|
divcasting=parse.select_one(".descriptif")
|
||||||
|
casting=divcasting.find_all(href=re.compile("biographie"))
|
||||||
|
count=0
|
||||||
|
for actor in casting:
|
||||||
|
casting[count]=actor.text
|
||||||
|
count+=1
|
||||||
|
divsynopsis=parse.select_one(".episode-synopsis")
|
||||||
|
img=divsynopsis.find_next('img')['data-src']
|
||||||
|
synopsis=divsynopsis.select_one(".d-b").text
|
||||||
|
return {'title':link['title'],'href':href,'casting':casting,'synopsis':remove_first_space(synopsis),'img':img}
|
||||||
|
|
||||||
|
|
||||||
|
def remove_first_space (string):
|
||||||
|
space_number=0
|
||||||
|
for char in string:
|
||||||
|
if char.isspace():
|
||||||
|
space_number+=1
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return string[space_number:]
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@ from flask import Flask,request,make_response,redirect,url_for,render_template,j
|
|||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from Jsonfile import JSONfile
|
from Jsonfile import JSONfile
|
||||||
from ReverseProxied import ReverseProxied
|
from ReverseProxied import ReverseProxied
|
||||||
|
import emission
|
||||||
data= JSONfile("chaine.json")
|
data= JSONfile("chaine.json")
|
||||||
app=Flask(__name__,static_folder = "dist/static",template_folder="dist")
|
app=Flask(__name__,static_folder = "dist/static",template_folder="dist")
|
||||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||||
@ -20,7 +20,15 @@ def get_chaine(num):
|
|||||||
@app.route('/api/v1/chaine/', methods=['put'])
|
@app.route('/api/v1/chaine/', methods=['put'])
|
||||||
def update_list():
|
def update_list():
|
||||||
data.parsechaine()
|
data.parsechaine()
|
||||||
return "OK"
|
return jsonify("OK")
|
||||||
|
|
||||||
|
@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 jsonify(chaine)
|
||||||
|
else:
|
||||||
|
return jsonify(emission.parse_emmission(chaine))
|
||||||
|
|
||||||
##@app.errorhandler(404)
|
##@app.errorhandler(404)
|
||||||
##def ma_page_404(error):
|
##def ma_page_404(error):
|
||||||
|
Loading…
Reference in New Issue
Block a user