correction bug chemin de fichier relatif

This commit is contained in:
vincent 2018-01-24 21:04:41 +01:00
parent 4cb0c6028e
commit 0f8a7521d3

View File

@ -3,11 +3,13 @@ from bs4 import BeautifulSoup
import urllib.request import urllib.request
import json import json
import sys import sys
import os
class Interface: class Interface:
def __init__(self): def __init__(self):
self.data = load_jsonfile('chaine.json') self.datafilepath=os.path.dirname(sys.argv[0])+"/chaine.json"
self.data = load_jsonfile(self.datafilepath)
self.fenetre = Tk() self.fenetre = Tk()
self.fenetre.title("recherche de chaine") self.fenetre.title("recherche de chaine")
self.value = StringVar() self.value = StringVar()
@ -51,14 +53,14 @@ class Interface:
self.value.set("") self.value.set("")
def click_reset(self): def click_reset(self):
print("exit") print("reset")
self.fenetre.quit self.fenetre.quit
self.label2["text"] = "" self.label2["text"] = ""
self.fenetre.mainloop self.fenetre.mainloop
def click_update(self): def click_update(self):
parsechaine() parsechaine(self.datafilepath)
self.data = load_jsonfile('chaine.json') self.data = load_jsonfile(self.datafilepath)
self.label2["text"] += "update chaine done"+"\r" self.label2["text"] += "update chaine done"+"\r"
@ -77,7 +79,7 @@ def RepresentsInt(s):
return False return False
def parsechaine(): def parsechaine(file):
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)
@ -98,13 +100,15 @@ def parsechaine():
#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(file, 'w', encoding='utf-8') as f:
json.dump(liste_chaine, f, indent=4) json.dump(liste_chaine, f, indent=4)
interface = Interface() interface = Interface()
if len(sys.argv) > 1: if len(sys.argv) > 1:
arg = True arg = True