correction syntaxique

This commit is contained in:
vincent 2018-01-22 21:46:53 +01:00
parent c98730cef0
commit e129a0643c

View File

@ -6,20 +6,20 @@ import urllib.request
import json import json
import sys import sys
def click (): def click():
print (value.get()) print(value.get())
try: try:
label2["text"]+=data[value.get()]+"\r" label2["text"] += data[value.get()]+"\r"
print(data[value.get()]) print(data[value.get()])
except KeyError: except KeyError:
print ("numero de chaine inconnue") print("numero de chaine inconnue")
label2["text"]+="numero de chaine inconnue"+"\r" label2["text"] += "numero de chaine inconnue"+"\r"
value.set("") value.set("")
def click_reset (): def click_reset():
print ("exit") print("exit")
fenetre.quit fenetre.quit
label2["text"]="" label2["text"] = ""
fenetre.mainloop fenetre.mainloop
@ -37,30 +37,30 @@ def RepresentsInt(s):
except TypeError: except TypeError:
return False return False
def parsechaine(): def parsechaine():
URL='https://fr.wikipedia.org/wiki/Liste_des_cha%C3%AEnes_de_Canal' URL = 'https://fr.wikipedia.org/wiki/Liste_des_cha%C3%AEnes_de_Canal'
liste_chaine={} liste_chaine = {}
response = urllib.request.urlopen(URL) response = urllib.request.urlopen(URL)
html = response.read() html = response.read()
parse=BeautifulSoup(html,"html.parser") parse = BeautifulSoup(html,"html.parser")
for item in parse.find_all('table'): for item in parse.find_all('table'):
if (item.get("class") == ['wikitable'] or item.get("class") == ['wikitable', 'sortable'] ): if (item.get("class") == ['wikitable'] or item.get("class") == ['wikitable', 'sortable']):
for tr in item.find_all('tr'): for tr in item.find_all('tr'):
firstTD=tr.find() firstTD = tr.find()
num=firstTD.string num = firstTD.string
if RepresentsInt(num): if RepresentsInt(num):
#print (num) #print(num)
if RepresentsInt(firstTD.find_next().string): if RepresentsInt(firstTD.find_next().string):
#print (firstTD.find_next().find_next().string) #print(firstTD.find_next().find_next().string)
liste_chaine[num]=firstTD.find_next().find_next().string liste_chaine[num] = firstTD.find_next().find_next().string
else: else:
#print (firstTD.find_next().string) #print(firstTD.find_next().string)
liste_chaine[num]=firstTD.find_next().string liste_chaine[num] = firstTD.find_next().string
print(json.dumps(liste_chaine, indent=4)) print(json.dumps(liste_chaine, indent=4))
with open('chaine.json', 'w', encoding='utf-8') as f: with open('chaine.json', 'w', encoding='utf-8') as f:
json.dump(liste_chaine, f, indent=4) json.dump(liste_chaine, f, indent=4)
data=load_jsonfile('chaine.json') data = load_jsonfile('chaine.json')
label2["text"]+="update chaine done"+"\r" label2["text"] += "update chaine done"+"\r"
def enter(evt): def enter(evt):
click() click()
@ -70,36 +70,36 @@ def eventreset(evt):
data=load_jsonfile('chaine.json') data = load_jsonfile('chaine.json')
fenetre = Tk() fenetre = Tk()
fenetre.title("recherche de chaine") fenetre.title("recherche de chaine")
value = StringVar() value = StringVar()
if(len(sys.argv)>1): if len(sys.argv) > 1:
arg=True arg = True
else: else:
value.set("") value.set("")
arg=False arg = False
label=Label(fenetre,text="entrer numero de chaine") label = Label(fenetre, text="entrer numero de chaine")
entree = Entry(fenetre, textvariable=value, width=30) entree = Entry(fenetre, textvariable=value, width=30)
frame =Frame(fenetre) frame = Frame(fenetre)
label2=Label(fenetre, text="") label2 = Label(fenetre, text="")
bouton_update_base= Button(fenetre,text="update la base de chaine",command=parsechaine) bouton_update_base = Button(fenetre, text="update la base de chaine", command=parsechaine)
bouton=Button(frame, text="OK", command=click) bouton = Button(frame, text="OK", command=click)
reset=Button(frame, text="reset",command=click_reset) reset = Button(frame, text="reset", command=click_reset)
label.pack() label.pack()
entree.pack() entree.pack()
entree.focus_set() entree.focus_set()
frame.pack() frame.pack()
bouton.pack(side = LEFT) bouton.pack(side=LEFT)
reset.pack(side = RIGHT) reset.pack(side=RIGHT)
label2.pack() label2.pack()
bouton_update_base.pack() bouton_update_base.pack()
fenetre.bind("<Key-Return>",enter) fenetre.bind("<Key-Return>", enter)
fenetre.bind("<Key-Escape>",eventreset) fenetre.bind("<Key-Escape>", eventreset)
if (arg==True): if arg == True:
for i in sys.argv[1:]: for i in sys.argv[1:]:
value.set(i) value.set(i)
click() click()