From 32aa9e84ee635b37f4cff37112e3e62837c914f4 Mon Sep 17 00:00:00 2001 From: Lionel Date: Tue, 16 Oct 2018 16:54:47 +0200 Subject: YOUPI on a bien mis de l'ordre dans foldercreating.py. On est presque au bout. Certains diront que ce code n'est pas assez modulable et tourné vers l'OOP mais je m'en fous pour l'instant. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- foldercreating.py | 56 +++++++++++++++++++++++++++---------------------------- inputs.py | 3 +-- main.py | 4 ++-- randoweb.py | 7 +++---- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/foldercreating.py b/foldercreating.py index a6fa34f..c1f4b23 100644 --- a/foldercreating.py +++ b/foldercreating.py @@ -7,35 +7,14 @@ import errmsg as e #(foldernames[0].split(' ')[0]+"-"+foldernames[0].split(' ')[2]).lower() => cirque-cilaos . ce formating sera pratique lors de la récupération sur site web thehome=os.path.expanduser("~") -thefolder="/Randopitons" -default_folder=thehome+thefolder - - -def mkfolder(maptype,choice): - folderptr=choice-1 - fullpath=thehome+"/"+foldernames[folderptr] - try: - if foldernames[folderptr] == "All": - for foldernames in totalfolders: - os.mkdir(os.path.join(thehome,str(foldernames))) - #subprocess.call("rm -d "+fullpath) - print "All folders were created successfully" - else: - os.mkdir(fullpath) - print "Folder "+fullpath+"was created successfully" - - - for foldernames in tolimit: - os.mkdir(os.path.join(thehome,str(foldernames))) - - except OSError, e: - print e.os - print format(e) +defoldername="/Randopitons" +def_folder=thehome+defoldername +fullpath=thehome+"/"+foldernames[regionptr] def mainfolder(): try: - chosing_folder=input("\n\nWhich folder would you want to download the files to [Default to home directory "+default_folder+"]") - print "Folder "+chosing_folder+" was created successfully" + a_folder=input("\n\nWhich folder would you want to download the files to [Default to home directory "+def_folder+"]") + print "Folder "+a_folder+" was created successfully" except OSError, e: #errors out if folder exists else print the error (can be permissions or anything else) if e.errno == os.errno.EEXIST: @@ -45,7 +24,28 @@ def mainfolder(): print format(e) pass except SyntaxError: - print "\nCreating default folder "+default_folder+" ..." - os.mkdir(default_folder) + print "\nCreating default folder "+def_folder+" ..." + os.mkdir(def_folder) + +def mkfolder(choice): + regionptr=choice-1 + try: + os.mkdir(os.path.join(thehome,foldernames[regionptr])) + except OSError, e: + print e.os + print format(e) + + +def mkallfolder(choice): + try: + if choice == 10: + for foldernames in range(9): + os.mkdir(os.path.join(thehome,str(foldernames))) + #subprocess.call("rm -d "+fullpath) + print "All folders were created successfully" + except OSError, e: + print e.os + print format(e) + #print "Program ended." diff --git a/inputs.py b/inputs.py index df067d2..cc00de3 100644 --- a/inputs.py +++ b/inputs.py @@ -16,7 +16,6 @@ def mapfileinput(): except (KeyboardInterrupt, SystemExit): print e.sigkill exit() - return maptype @@ -42,7 +41,7 @@ def regioninput(): print e.sigkill exit() except SyntaxError: - print("\nDefaulting to All. If this isn't what you wanted, you can always interrupt the script by pressing "+BOLD+"CTRL+C"+ENDC) + print("\nDefaulting to All. If this isn't what you wanted, you can always interrupt the script by pressing "+clc.bold+"CTRL+C"+clc.endc) zone = 10; except NameError: print "\nPlease enter a number between 1 and 10." diff --git a/main.py b/main.py index 3a85d8b..6cabb96 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,6 @@ import colorcode as clc import foldercreating as fdc foldernames=["Cirque de Cilaos","Cirque de Mafate","Cirque de Salazie","Est","Nord","Ouest","Sud","Volcan","Ailleurs","All"] -totalfolders=foldernames randonb=[] basicfilename="" print clc.bold+"\n\nWelcome ! \nWith this script, you will be able to download gpx,trk and kml traces for hitchiking on the Reunion Isle."+clc.endc @@ -14,6 +13,7 @@ loginmail() logipass() filetype=mapfileinput() +zonechoice=regioninput() if filetype==1: basicfilename="f.gpx" @@ -23,7 +23,7 @@ else filetype==3: basicfilename="f.kml" mapparsing(filetype,basicfilename) - +mkfolder(filetype,zonechoice) payload = { 'mail': MAIL, diff --git a/randoweb.py b/randoweb.py index 6bc18bb..332bdad 100644 --- a/randoweb.py +++ b/randoweb.py @@ -11,14 +11,13 @@ def randoweb(): post('https://randopitons.re/connexion', data=payload) region = c.get('https://randopitons.re/randonnees/region/'+region) wsite=bs(region) + for i in wsite.find_all('tr'): + randonb.append(i.get("rid")) except SSLError, sslerr: print e.sslerr - - - for i in wsite.find_all('tr'): - randonb.append(i.get("rid")) + try: for i in randonb: -- cgit v1.2.3-70-g09d2