Merge branch 'dev' of vincent/chainetv_web into master
This commit is contained in:
commit
4e73a980b8
@ -1,11 +1,13 @@
|
|||||||
from flask import Blueprint, jsonify, request,make_response,redirect,url_for,render_template,current_app
|
from flask import Blueprint, jsonify, request,make_response,redirect,url_for,render_template,current_app
|
||||||
from .Jsonfile import JSONfile
|
from .Jsonfile import JSONfile
|
||||||
from . import emission
|
from .emission import Emmission
|
||||||
import jwt
|
import jwt
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
data= JSONfile("chaine.json")
|
data= JSONfile("chaine.json")
|
||||||
|
emmission= Emmission()
|
||||||
|
|
||||||
def token_required(f):
|
def token_required(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
@ -68,7 +70,8 @@ def get_emmission(num):
|
|||||||
if (chaine == "numero de chaine inconnue"):
|
if (chaine == "numero de chaine inconnue"):
|
||||||
return make_response("",204)
|
return make_response("",204)
|
||||||
else:
|
else:
|
||||||
return jsonify(emission.parse_emmission(chaine))
|
|
||||||
|
return jsonify(emmission.parse_emmission(chaine))
|
||||||
|
|
||||||
#@api.route('/register/', methods=('POST',))
|
#@api.route('/register/', methods=('POST',))
|
||||||
#def register():
|
#def register():
|
||||||
|
@ -1,28 +1,37 @@
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import re
|
import re
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
#debug
|
#debug
|
||||||
#import pprint
|
#import pprint
|
||||||
|
|
||||||
def parse_emmission(strsearch):
|
class Emmission(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._LoadreferencePage()
|
||||||
|
|
||||||
|
def _LoadreferencePage(self):
|
||||||
URL="https://www.programme-tv.net/programme/canal-5/"
|
URL="https://www.programme-tv.net/programme/canal-5/"
|
||||||
try:
|
try:
|
||||||
response = urllib.request.urlopen(URL)
|
response = urllib.request.urlopen(URL)
|
||||||
except urllib.error.URLError:
|
except urllib.error.URLError:
|
||||||
return False
|
return None
|
||||||
|
print("load")
|
||||||
|
self.html = BeautifulSoup(response.read(),"html.parser")
|
||||||
|
self.timestamp=datetime.utcnow()
|
||||||
|
|
||||||
html = response.read()
|
def parse_emmission(self,strsearch):
|
||||||
parse=BeautifulSoup(html,"html.parser")
|
if (self.timestamp > self.timestamp+timedelta(minutes=5)):
|
||||||
|
self._LoadreferencePage()
|
||||||
strsearch=strsearch.replace('É','E')
|
strsearch=strsearch.replace('É','E')
|
||||||
linkchaine=parse.find(text=re.compile(re.escape(strsearch)))
|
linkchaine=self.html.find(text=re.compile(re.escape(strsearch)))
|
||||||
if linkchaine == None:
|
if linkchaine == None:
|
||||||
return "can't find channel"
|
return "can't find channel"
|
||||||
link = linkchaine.parent.parent.find_next_sibling().find("a")
|
link = linkchaine.parent.parent.find_next_sibling().find("a")
|
||||||
href = link['href']
|
href = link['href']
|
||||||
response = urllib.request.urlopen(href)
|
response = urllib.request.urlopen(href)
|
||||||
html = response.read()
|
parse=BeautifulSoup(response.read(),"html.parser")
|
||||||
parse=BeautifulSoup(html,"html.parser")
|
|
||||||
divcasting=parse.select_one(".descriptif")
|
divcasting=parse.select_one(".descriptif")
|
||||||
if (divcasting):
|
if (divcasting):
|
||||||
casting=divcasting.find_all(href=re.compile("biographie"))
|
casting=divcasting.find_all(href=re.compile("biographie"))
|
||||||
|
Loading…
Reference in New Issue
Block a user