create class jsonfile
This commit is contained in:
parent
c12341cd4b
commit
98e07cda07
73
chaineTV.py
73
chaineTV.py
@ -90,9 +90,8 @@ class emmisionGUI(Frame):
|
||||
|
||||
class Interface:
|
||||
|
||||
def __init__(self):
|
||||
self.datafilepath=os.path.dirname(os.path.realpath(__file__))+"/chaine.json"
|
||||
self.data = load_jsonfile(self.datafilepath)
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
self.fenetre = Tk()
|
||||
self.fenetre.title("recherche de chaine")
|
||||
self.value = StringVar()
|
||||
@ -131,11 +130,11 @@ class Interface:
|
||||
|
||||
|
||||
try:
|
||||
strlink=geturlprogrammetv(self.data[value])
|
||||
link= Labbelink(self.resultframe.interior,self.data[value],strlink)
|
||||
strlink=geturlprogrammetv(self.data.get_chaine(value))
|
||||
link= Labbelink(self.resultframe.interior,self.data.get_chaine(value),strlink)
|
||||
link.pack()
|
||||
self.resultframe.update()
|
||||
print(self.data[value])
|
||||
print(self.data.get_chaine(value))
|
||||
emision=parse_emmission(strlink)
|
||||
if emision:
|
||||
if emision == "can't find show":
|
||||
@ -160,8 +159,7 @@ class Interface:
|
||||
|
||||
|
||||
def click_update(self):
|
||||
parsechaine(self.datafilepath)
|
||||
self.data = load_jsonfile(self.datafilepath)
|
||||
self.data.parsechaine()
|
||||
labelupdate = Label(self.resultframe, text="update chaine done"+"\r")
|
||||
labelupdate.pack()
|
||||
|
||||
@ -169,27 +167,20 @@ class Interface:
|
||||
webbrowser.open_new(link)
|
||||
|
||||
|
||||
class JSONfile:
|
||||
|
||||
|
||||
def load_jsonfile(file):
|
||||
def __init__(self,filename):
|
||||
import os,json
|
||||
self.datafilepath=os.path.dirname(os.path.realpath(__file__))+"/"+filename
|
||||
try:
|
||||
with open(file, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
with open(self.datafilepath, 'r', encoding='utf-8') as f:
|
||||
self.data=json.load(f)
|
||||
except FileNotFoundError:
|
||||
parsechaine(file)
|
||||
with open(file, 'r', encoding='utf-8') as f:
|
||||
return json.load(f)
|
||||
self.parsechaine()
|
||||
|
||||
def RepresentsInt(s):
|
||||
try:
|
||||
int(s)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
def parsechaine(file):
|
||||
def get_chaine(self,number):
|
||||
return self.data[number]
|
||||
def parsechaine(self):
|
||||
|
||||
URL = 'https://fr.wikipedia.org/wiki/Liste_des_cha%C3%AEnes_de_Canal'
|
||||
liste_chaine = {}
|
||||
@ -212,8 +203,20 @@ def parsechaine(file):
|
||||
#print(firstTD.find_next().string)
|
||||
liste_chaine[int(num)] = firstTD.find_next().text
|
||||
print(json.dumps(liste_chaine, indent=4))
|
||||
with open(file, 'w', encoding='utf-8') as f:
|
||||
self.data=liste_chaine
|
||||
with open(self.datafilepath, 'w', encoding='utf-8') as f:
|
||||
json.dump(liste_chaine, f, indent=4)
|
||||
def __repr__(self):
|
||||
return str(self.data)
|
||||
|
||||
def RepresentsInt(s):
|
||||
try:
|
||||
int(s)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
def geturlprogrammetv(strsearch):
|
||||
strsearch=unicodedata.normalize('NFD', strsearch).encode('ascii', 'ignore')
|
||||
@ -241,7 +244,7 @@ def parse_emmission(URL):
|
||||
casting=divcasting.find_all(href=re.compile("biographie"))
|
||||
count=0
|
||||
for actor in casting:
|
||||
casting[i]=actor.text
|
||||
casting[count]=actor.text
|
||||
count+=1
|
||||
divsynopsis=parse.select_one(".episode-synopsis")
|
||||
img=divsynopsis.find_next('img')['data-src']
|
||||
@ -259,9 +262,7 @@ def remove_first_space (string):
|
||||
return string[space_number:]
|
||||
|
||||
|
||||
def cli(num):
|
||||
datafilepath=os.path.dirname(os.path.realpath(__file__))+"/chaine.json"
|
||||
data = load_jsonfile(datafilepath)
|
||||
def cli(num,data):
|
||||
print(num)
|
||||
try:
|
||||
print(data[num])
|
||||
@ -283,11 +284,13 @@ def cli(num):
|
||||
else:
|
||||
print("pas de connection internet impossible de determiner l'émission du soir")
|
||||
print("")
|
||||
|
||||
data=JSONfile("chaine.json")
|
||||
if len(sys.argv) > 1:
|
||||
for i in sys.argv[1:]:
|
||||
if i =="update":
|
||||
parsechaine(os.path.dirname(os.path.realpath(__file__))+"/chaine.json")
|
||||
for arg in sys.argv[1:]:
|
||||
if arg =="update":
|
||||
data.parsechaine()
|
||||
else:
|
||||
cli(i)
|
||||
cli(arg,data.data)
|
||||
else:
|
||||
Interface().mainloop()
|
||||
Interface(data).mainloop()
|
Loading…
Reference in New Issue
Block a user