From cb352e489e5ac5f927500428a95a1b7edf9f24e0 Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 22 Jan 2018 19:11:29 +0100 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20json=20file=20parser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chaine.json | 333 ++++++++++++++++++++++++++++++++++++++++++++++++++ chaineTV.py | 27 ++-- parserHTML.py | 45 +++++++ 3 files changed, 396 insertions(+), 9 deletions(-) create mode 100644 chaine.json create mode 100644 parserHTML.py diff --git a/chaine.json b/chaine.json new file mode 100644 index 0000000..62be237 --- /dev/null +++ b/chaine.json @@ -0,0 +1,333 @@ +{ + "0": "Accueil", + "1": "TF1", + "2": "France 2", + "3": "France 3", + "4": "Canal+", + "5": "France 5", + "6": "M6", + "7": "Arte", + "8": "\u00c0 la une Canal", + "9": "CANAL+", + "10": "Canal+ Cin\u00e9ma", + "11": "Canal+ Sport", + "12": "Canal+ S\u00e9ries", + "13": "Canal+ Family", + "14": "Canal+ D\u00e9cal\u00e9", + "15": "Canal \u00e0 la demande", + "16": "Canal VOD", + "17": "Canalplay", + "19": "Canal Evenement", + "20": "Cin\u00e9+ Premier", + "21": "Cin\u00e9+ Frisson", + "22": "Cin\u00e9+ \u00c9motion", + "23": "Cin\u00e9+ Famiz", + "24": "Cin\u00e9+ Club", + "25": "Cin\u00e9+ Classic", + "26": "OCS Max", + "27": "OCS City", + "28": "OCS Choc", + "29": "OCS G\u00e9ants", + "30": "Disney Cinema", + "31": "TCM Cin\u00e9ma", + "32": "Paramount Channel", + "33": "Action", + "34": "SundanceTV", + "35": "Canal", + "38": "Fox Play", + "40": "Com\u00e9die+", + "41": "Polar+", + "42": "Warner TV", + "43": "S\u00e9rie Club", + "44": "MTV", + "45": "Elle Girl", + "46": "Non Stop People", + "47": "Novelas TV", + "48": "MCM", + "49": "Game One", + "50": "J-One", + "51": "Mangas", + "52": "AB1", + "53": "TV Breizh", + "54": "T\u00e9va", + "55": "Paris Premi\u00e8re", + "56": "RTL9", + "57": "BET", + "58": "C8", + "59": "W9", + "60": "TMC", + "61": "NT1", + "62": "NRJ12", + "63": "France 4", + "64": "CStar", + "65": "France \u00d4", + "66": "HD1", + "67": "6ter", + "68": "Num\u00e9ro 23", + "69": "Ch\u00e9rie 25", + "71": "TV5 Monde", + "75": "myZen.tv", + "77": "QVC", + "78": "M6 Boutique", + "79": "Astrocenter TV", + "80": "Plan\u00e8te+", + "81": "Plan\u00e8te+ CI", + "82": "Plan\u00e8te+ A&E", + "83": "Viceland", + "84": "Museum", + "85": "National Geographic", + "86": "Nat Geo Wild", + "87": "Voyage", + "88": "Ushua\u00efa TV", + "89": "Histoire", + "90": "Toute l'Histoire", + "91": "Science et Vie TV", + "92": "Animaux", + "93": "Trek", + "94": "Seasons", + "95": "Chasse et P\u00eache", + "96": "MB Live TV", + "97": "8 Mont-Blanc", + "98": "RMC D\u00e9couverte", + "99": "Mes Vid\u00e9os", + "100": "La Cha\u00eene m\u00e9t\u00e9o", + "101": "CNews", + "102": "BFM TV", + "103": "LCI", + "104": "France Info", + "105": null, + "106": "France 24", + "107": "La Cha\u00eene parlementaire", + "108": "BFM Business", + "109": "Bloomberg TV", + "110": "CNN International", + "111": "BBC World News", + "112": "CNBC Europe", + "113": "i24 News", + "114": "KTO", + "120": "Infosport+", + "121": "Eurosport 1", + "122": "Eurosport 2", + "123": "OM TV", + "124": "OL TV", + "125": "Onz\u00e9o", + "126": "Girondins TV", + "127": "AB Moteurs", + "128": "Equidia", + "130": "Mosa\u00efque beIN Sports", + "131": "beIN Sports 1", + "132": "beIN Sports 2", + "133": "beIN Sports 3", + "134": "Golf+", + "135": "Extreme Sports Channel", + "136": "Motorsport.tv", + "137": "L'\u00c9quipe", + "150": "Disney Junior", + "151": "Piwi+", + "152": "Nickelodeon Junior", + "153": "Mon Nickelodeon Junior", + "154": "TiJi", + "155": "Boomerang", + "156": "Cartoon Network", + "157": "Nickelodeon", + "158": "Nickelodeon+1", + "159": "T\u00e9l\u00e9toon+", + "160": "T\u00e9l\u00e9toon+1", + "161": "Disney XD", + "162": "Canal J", + "163": "Boing", + "164": "Toonami", + "165": "Nickelodeon Teen", + "166": "Disney Channel", + "167": "Disney Channel +1", + "168": "Baby TV", + "169": "Gulli", + "170": "MTV Hits", + "171": "myMTV", + "172": "M6 Music", + "173": "NRJ Hits", + "174": "Trace Urban", + "175": "MCM Top", + "176": "RFM TV", + "177": "Melody", + "178": "Mezzo", + "179": "Mezzo Live HD", + "180": "Stingray Brava", + "181": "Stingray Djazz", + "199": "Mosa\u00efque des radios", + "200": "Nollywood TV", + "201": "A+", + "202": "Trace Africa", + "209": "Le Porn", + "210": "Pass XXL-Dorcel", + "211": "XXL", + "212": "Dorcel TV", + "213": "Dorcel XXX", + "214": "Libido TV", + "215": "Frenchlover TV", + "216": "Penthouse HD", + "217": "Penthouse Black", + "218": "Colmax TV", + "219": "Pink X", + "220": "Man-X", + "221": "Pass Pink X", + "250": "Multisports", + "251": "Foot+ 24/24", + "252": "Golf+", + "253": "Multisports 1", + "254": "Multisports 2", + "255": "Multisports 3", + "256": "Multisports 4", + "257": "Multisports 5", + "258": "Multisports 6", + "264": "beIN Sports Max 4", + "265": "beIN Sports Max 5", + "266": "beIN Sports Max 6", + "267": "beIN Sports Max 7", + "268": "beIN Sports Max 8", + "269": "beIN Sports Max 9", + "270": "beIN Sports Max 10", + "280": "Eurosport 360\u00b0 1", + "281": "Eurosport 360\u00b0 2", + "282": "Eurosport 360\u00b0 3", + "283": "Eurosport 360\u00b0 4", + "284": "Eurosport 360\u00b0 5", + "285": "Eurosport 360\u00b0 6", + "286": "Eurosport 360\u00b0 7", + "287": "Eurosport 360\u00b0 8", + "291": "Canalplay", + "292": "Canal VOD", + "293": "MyTF1", + "294": "6play M6", + "350": "France 3 Alpes", + "351": "France 3 Alsace", + "352": "France 3 Aquitaine", + "353": "France 3 Auvergne", + "354": "France 3 Basse-Normandie", + "355": "France 3 Bourgogne", + "356": "France 3 Bretagne", + "357": "France 3 Centre-Val de Loire", + "358": "France 3 Champagne-Ardenne", + "359": "France 3 Corse", + "360": "France 3 C\u00f4te d'Azur", + "361": "France 3 Franche-Comt\u00e9", + "362": "France 3 Haute-Normandie", + "363": "France 3 Languedoc-Roussillon", + "364": "France 3 Limousin", + "365": "France 3 Lorraine", + "366": "France 3 Midi-Pyr\u00e9n\u00e9es", + "367": "France 3 Nord-Pas-de-Calais", + "368": "France 3 Paris \u00cele-de-France", + "369": "France 3 Pays de la Loire", + "370": "France 3 Picardie", + "371": "France 3 Poitou-Charentes", + "372": "France 3 Provence-Alpes", + "373": "France 3 Rh\u00f4ne-Alpes", + "400": "Al Jazeera", + "401": "France 24 Arabic", + "402": "2M Monde", + "403": "Canal Alg\u00e9rie", + "404": "A3", + "405": "Tunisie 1", + "407": "France 24 English", + "408": "Al Jazeera English", + "409": "Sky News International", + "414": "RTP Internacional", + "415": "Record Internacional", + "416": "Tele Sur", + "418": "TVE International", + "419": "Canal 24 horas", + "420": "Andaluc\u00eda TV", + "421": "Televisi\u00f3n de Galicia", + "422": "Cubavisi\u00f3n Internacional", + "424": "BVN", + "426": "DW-TV", + "427": "RTL Television", + "428": "RTL II", + "429": "Super RTL", + "430": "Das Erste", + "431": "tagesschau24", + "433": "One", + "434": "BR Fernsehen", + "435": "ARD-alpha", + "436": "RBB Berlin", + "437": "HR-Fernsehen", + "438": "MDR Fernsehen", + "439": "NDR Fernsehen", + "440": "RBB Brandenburg", + "441": "Phoenix", + "442": "SR Fernsehen", + "443": "WDR Fernsehen", + "444": "3sat", + "445": "KiKA", + "446": "Arte Allemagne", + "447": null, + "448": "ZDFinfo", + "450": "ZDFneo", + "451": "Sport1", + "452": "Kabel eins", + "453": "Sat.1 Gold", + "454": "N24", + "455": "Sat.1", + "456": "ProSieben", + "457": "VOX", + "458": "n-tv", + "459": "Tele 5", + "460": "Sonnenklar.TV", + "461": null, + "463": "Sonlife", + "464": "God TV", + "466": "EWTN", + "467": "TV Trwam", + "469": "CGTN Documentary", + "470": "CGTN", + "471": "CGTN fran\u00e7ais", + "472": "Arirang TV", + "473": "NHK World", + "474": "RT", + "475": "TRT T\u00fcrk", + "476": null, + "600": "France Culture", + "601": "France Musique", + "602": "FIP", + "603": "France Info", + "604": "France Inter", + "605": "France Bleu", + "606": "Mouv'", + "607": "Monte Carlo Doualiya", + "608": "RFI", + "610": "Europe 1", + "611": "Virgin Radio", + "612": "RFM", + "613": "RTL", + "614": "RTL2", + "615": "Fun Radio", + "616": "NRJ", + "617": "Ch\u00e9rie", + "618": "Rire & Chansons", + "619": "NOSTALGIE", + "620": "RMC", + "621": "BFM Business", + "622": "Sud Radio", + "623": "TSF Jazz", + "624": "Radio Nova", + "625": "Radio FG", + "627": "Contact FM", + "629": "Jazz Radio", + "630": "Skyrock", + "631": "Radio Classique", + "633": "O\u00dcI FM", + "635": "Radio Notre-Dame", + "636": "Radio Alfa", + "638": "Beur FM", + "639": "BBC World Service", + "640": "BBC Arabic", + "641": "Radio Courtoisie", + "490": "Espace client", + "777": "Num\u00e9rotations", + "888": "Cha\u00eene de droits", + "922": "info Technique", + "998": "Nouveaut\u00e9s", + "999": "Mosa\u00efque", + "2018": "myCANAL" +} \ No newline at end of file diff --git a/chaineTV.py b/chaineTV.py index 7c2867b..7af1278 100644 --- a/chaineTV.py +++ b/chaineTV.py @@ -1,10 +1,17 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from tkinter import * +from bs4 import BeautifulSoup +import urllib.request +import json def click (): - print (value.get()) - label2["text"]+=value.get()+"\r" + print (value.get()) + try: + label2["text"]+=data[value.get()]+"\r" + except KeyError: + label2["text"]+="numero de chaine inconnue"+"\r" + def click_reset (): print ("exit") @@ -12,19 +19,21 @@ def click_reset (): label2["text"]="" fenetre.mainloop -def check_channel(numero): - return { - 'a': 1, - 'b': 2 - }.get(numero, "chaine inconnue") +def load_jsonfile(file): + with open(file, 'r', encoding='utf-8') as f: + return json.load(f) + + + +data=load_jsonfile('chaine.json') fenetre = Tk() value = StringVar() -value.set("texte par défaut") +value.set("") +label=Label(fenetre,text="entrer numero de chaine") entree = Entry(fenetre, textvariable=value, width=30) frame =Frame(fenetre) -label = Label(fenetre, text="entrer text ") label2=Label(fenetre, text="") bouton=Button(frame, text="OK", command=click) reset=Button(frame, text="reset",command=click_reset) diff --git a/parserHTML.py b/parserHTML.py new file mode 100644 index 0000000..7847feb --- /dev/null +++ b/parserHTML.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from bs4 import BeautifulSoup +import urllib.request +import json + +def RepresentsInt(s): + try: + int(s) + return True + except ValueError: + return False + except TypeError: + return False +def parsechaine(): + URL='https://fr.wikipedia.org/wiki/Liste_des_cha%C3%AEnes_de_Canal' + liste_chaine={} + response = urllib.request.urlopen(URL) + html = response.read() + parse=BeautifulSoup(html,"html.parser") + for item in parse.find_all('table'): + if (item.get("class") == ['wikitable', 'sortable']): + for tr in item.find_all('tr'): + + firstTD=tr.find() + num=firstTD.string + if RepresentsInt(num): + #print (num) + if RepresentsInt(firstTD.find_next().string): + #print (firstTD.find_next().find_next().string) + liste_chaine[num]=firstTD.find_next().find_next().string + else: + #print (firstTD.find_next().string) + liste_chaine[num]=firstTD.find_next().string + print(json.dumps(liste_chaine, indent=4)) + with open('chaine.json', 'w', encoding='utf-8') as f: + json.dump(liste_chaine, f, indent=4) + +def load_jsonfile(file): + with open(file, 'r', encoding='utf-8') as f: + return json.load(f) + +data=load_jsonfile('chaine.json') +print(data["0"]) \ No newline at end of file