From 86ccdbee7586919197a092ac39cc5b94b4af9fe6 Mon Sep 17 00:00:00 2001 From: vincent Date: Sat, 18 Aug 2018 19:34:55 +0200 Subject: [PATCH] correction cas ou la chaine n'est pas une chaine referencer --- chaineTV.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/chaineTV.py b/chaineTV.py index f32f85a..097608b 100644 --- a/chaineTV.py +++ b/chaineTV.py @@ -148,9 +148,12 @@ def parse_emmission(URL): response = urllib.request.urlopen(URL) except urllib.error.URLError: return False + html = response.read() parse=BeautifulSoup(html,"html.parser") link=parse.select_one(".prog_name") + if link == None: + return "can't find show" href="https://www.programme-tv.net"+link['href'] response = urllib.request.urlopen(href) html = response.read() @@ -179,16 +182,19 @@ def cli(num): return emision=parse_emmission(geturlprogrammetv(data[num])) if emision: - print("emmision ce soir: "+emision["title"]) - if len(emision['casting']) > 0: - print("réalisateur: "+emision['casting'][0]) - print("acteur: "+str(emision['casting'][1:])) - print("synopsys: " +emision['synopsis']) - print("lien: "+emision['href']) + if emision == "can't find show": + print ("impssible de parser cette chaine") + else: + print("emmision ce soir: "+emision["title"]) + if len(emision['casting']) > 0: + print("réalisateur: "+emision['casting'][0]) + print("acteur: "+str(emision['casting'][1:])) + print("synopsys: " +emision['synopsis']) + print("lien: "+emision['href']) else: print("pas de connection internet impossible de determiner l'émission du soir") - + print("") if len(sys.argv) > 1: for i in sys.argv[1:]: if i =="update":