diff options
author | Lionel <lionel.miquel46@gmail.com> | 2018-10-04 00:22:29 +0200 |
---|---|---|
committer | Lionel <lionel.miquel46@gmail.com> | 2018-10-04 00:22:29 +0200 |
commit | 0943dd142523b53e3748987fd16c77e6567c2fab (patch) | |
tree | 8c337dfc50793faf14eae2c28506ab55aa541515 | |
parent | 8300c7e61860d2dedb85537041f96e49fa69eb87 (diff) | |
download | randopitons-0943dd142523b53e3748987fd16c77e6567c2fab.tar.gz randopitons-0943dd142523b53e3748987fd16c77e6567c2fab.zip |
Ouai déso pour les injures dans le code, faut bien décompresser défois. Sinon un peu plus de clarté, on suit un peu plus le principe de la fonction qui fait une chose et qui le fait bien. Division entre les demandes d'input utilisateur, du parsing des fichiers de randonnées, de la création des dossiers, requêtes vers le web pour télécharger nos fameuses cartes. Et des codes pour les couleurs. Plus à venir, notamment avec les codes d'erreurs
-rw-r--r-- | colorcode.py | 9 | ||||
-rw-r--r-- | foldercreating.py | 71 | ||||
-rw-r--r-- | init.py | 34 | ||||
-rw-r--r-- | inputs.py | 48 | ||||
-rw-r--r-- | mapsparsing.py | 45 | ||||
-rw-r--r-- | randoweb.py (renamed from posttest.py) | 12 |
6 files changed, 128 insertions, 91 deletions
diff --git a/colorcode.py b/colorcode.py new file mode 100644 index 0000000..8263420 --- /dev/null +++ b/colorcode.py @@ -0,0 +1,9 @@ +#Simplified color codes here for error/warning/ok and the such.. messages +HEADER = '\033[95m' +OKBLUE = '\033[94m' +OKGREEN = '\033[92m' +WARNING = '\033[93m' +FAIL = '\033[91m' +ENDC = '\033[0m' +BOLD = '\033[1m' +UNDERLINE = '\033[4m' diff --git a/foldercreating.py b/foldercreating.py index ea8fd24..a95c169 100644 --- a/foldercreating.py +++ b/foldercreating.py @@ -5,28 +5,9 @@ import time #global foldernames #(foldernames[0].split(' ')[0]+"-"+foldernames[0].split(' ')[2]).lower() => cirque-cilaos . ce formating sera pratique pour le site web - -foldernames=["Cirque de Cilaos","Cirque de Mafate","Cirque de Salazie","Est","Nord","Ouest","Sud","Volcan","Ailleurs","All"] -totalfolders=foldernames thehome=os.path.expanduser("~") thefolder="/Randopitons" -default_folder=thehome+thefolder -choice = 0 -maptype = 0 - -class colrs: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' - -#def print colrs.FAIL+("Operating System error: {0}".format(e))+colrs.ENDC: - #print colrs.FAIL+("Operating System error: {0}".format(e))+colrs.ENDC - +default_folder=thehome+thefolder ##def dlmap(maptype,choice): # folderptr=choice-1 @@ -71,60 +52,10 @@ except SyntaxError: -print """\n Which zone you would want to download ? -1. Cirque de Cilaos (Cilaos' Circus) -2. Cirque de Mafate (Mafate's Circus) -3. Cirque de Salazie (Salazie's Circus) -4. Est (East) -5. Nord (North) -6. Ouest (West) -7. Sud (South) -8. Volcan (Volcano) -9. Ailleurs (Elsewhere) -10. All \n""" - - - ##================CHOSING CHOICE (heh)============== -while choice < 1 or choice > 10: - try: - choice = input("You must enter a number between 1 and 10. Your choice [Default is \"All\"]: ") - int(choice) - except (KeyboardInterrupt, SystemExit): - print colrs.WARNING+"\n\nProcess interrupted by CTRL+C or system."+colrs.ENDC - exit() - except SyntaxError: - choice = 10; - except NameError: - print "\nPlease enter a number between 1 and 10." - choice = 0 - #================DECLARING FOLDERNAMES============== - #================CHOSING MAPTYPE============== -print """\n Which map type you would want to download ? -1. gpx (GPS Exchange Format) -2. trk (CompeGPS Land Track File) -3. kml (Keyhole Markup Language)\n""" - -while maptype<1 or maptype>3: - try: - maptype = input("You must enter a number between 1 and 3. Your choice ? ") - int(maptype) - except (KeyboardInterrupt, SystemExit): - print colrs.WARNING+"\n\nProcess interrupted by CTRL+C or system."+colrs.ENDC - exit() - - - # raise - # time.sleep(3) - - #pass - - - - print "Program ended." @@ -1,19 +1,21 @@ import os +from choices import mapfileinput foldernames=["Cirque de Cilaos","Cirque de Mafate","Cirque de Salazie","Est","Nord","Ouest","Sud","Volcan","Ailleurs","All"] totalfolders=foldernames -thehome=os.path.expanduser("~") -thefolder="/Randopitons" -default_folder=thehome+thefolder -choice = 0 -maptype = 0 - -HEADER = '\033[95m' -OKBLUE = '\033[94m' -OKGREEN = '\033[92m' -WARNING = '\033[93m' -FAIL = '\033[91m' -ENDC = '\033[0m' -BOLD = '\033[1m' -UNDERLINE = '\033[4m' - -print(BOLD+"A FUCKING LEAF"+ENDC) + +print "\n\nWelcome ! \nWith this script, you will be able to download gpx,trk and kml traces for hitchiking on the Reunion Isle." + + + + + +mapfileinput() + + + + + + + + + diff --git a/inputs.py b/inputs.py new file mode 100644 index 0000000..6745c37 --- /dev/null +++ b/inputs.py @@ -0,0 +1,48 @@ +import colorcode + +def mapfileinput(): + maptype = 0 + print """\n Which map file extension you would want to download ? + 1. gpx (GPS Exchange Format) + 2. trk (CompeGPS Land Track File) + 3. kml (Keyhole Markup Language)\n""" + + while maptype<1 or maptype>3: + try: + maptype = input("You must enter a number between 1 and 3. Your choice ? ") + int(maptype) + except (KeyboardInterrupt, SystemExit): + print WARNING+"\n\nProcess interrupted by CTRL+C or system."+ENDC + exit() + + return maptype + + +def regioninput(): + zone = 0 + print """\n Which zone you would want to download ? + 1. Cirque de Cilaos (Cilaos' Circus) + 2. Cirque de Mafate (Mafate's Circus) + 3. Cirque de Salazie (Salazie's Circus) + 4. Est (East) + 5. Nord (North) + 6. Ouest (West) + 7. Sud (South) + 8. Volcan (Volcano) + 9. Ailleurs (Elsewhere) + 10. All \n""" + + while zone < 1 or zone > 10: + try: + zone = input("You must enter a number between 1 and 10. Your zone [Default is \"All\"]: ") + int(zone) + except (KeyboardInterrupt, SystemExit): + print WARNING+"\n\nProcess interrupted by CTRL+C or system."+ENDC + 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) + zone = 10; + except NameError: + print "\nPlease enter a number between 1 and 10." + zone = 0 + return zone diff --git a/mapsparsing.py b/mapsparsing.py new file mode 100644 index 0000000..4fc1cc5 --- /dev/null +++ b/mapsparsing.py @@ -0,0 +1,45 @@ +import xml.etree.ElementTree as xmlp +import re + +def gpxparsing(): + try: + tree=xmlp.parse('f.gpx') + root=tree.getroot() + filename=root[1][0].text+".gpx" + os.rename('f.gpx',filename) + except OSError, e: + print("Operating System error: {0}".format(e)) + except xml.etree.ElementTree.ParseError,e: + print("Something occured with the formating:{0} . File is not retrievable, passing on next download.".format(e)) + os.remove('f.gpx') + pass + return filename + + +def kmlparsing(): + + try: + tree=xmlp.parse('f.kml') + root=tree.getroot() + filename= root[0][10][1][0].text+".kml" + except OSError, e: + print("Operating System error: {0}".format(e)) + except xml.etree.ElementTree.ParseError,e: + print("Something occured with the formating:{0} . File is not retrievable, passing on next download.".format(e)) + os.remove('f.kml') + pass + return filename + +def trkparsing(): + try: + tree=xmlp.parse('f.gpx') + root=tree.getroot() + filename=root[1][0].text+".gpx" + os.rename('f.gpx',filename) + except OSError, e: + print("Operating System error: {0}".format(e)) + except xml.etree.ElementTree.ParseError,e: + print("Something occured with the formating:{0} . File is not retrievable, passing on next download.".format(e)) + os.remove('f.gpx') + pass + return filename diff --git a/posttest.py b/randoweb.py index 0ebd49b..c714a40 100644 --- a/posttest.py +++ b/randoweb.py @@ -1,13 +1,15 @@ from requests import session import getpass -import xml.etree.ElementTree as xmlp + import os from bs4 import BeautifulSoup as bs + + def main(region,maptype): - MAIL=raw_input("YUORE E-MAIL TO LOG IN TO RANDOPITONS.RE : ") - PSW=getpass.getpass(prompt="YUORE PASSWORD TO LOG IN TO RANDOPITONS.RE : ") + MAIL=raw_input("Your email to log in to randopitons.re : ") + PSW=getpass.getpass(prompt="Your password to log in to randopitons.re: ") payload = { @@ -19,7 +21,7 @@ def main(region,maptype): try: post('https://randopitons.re/connexion', data=payload) except SSLError, sslerr: - print "Erreur de certificat SSL" + print "SSL Certificate Error. Please check the time on your computer, adjust it accordingly, or wait a bit before retrying the downloads." region = c.get('https://randopitons.re/randonnees/region/'+region) wsite=bs(region) @@ -43,7 +45,7 @@ def main(region,maptype): except OSError, e: print("Operating System error: {0}".format(e)) except xml.etree.ElementTree.ParseError,e: - print("something occuredwith the formating:{0}".format(e)) + print("Something occured with the formating:{0} . File is not retrievable, passing on next download.".format(e)) os.remove('f.gpx') pass |