diff options
author | Lionel <lionel.miquel46@gmail.com> | 2018-10-04 08:13:08 +0200 |
---|---|---|
committer | Lionel <lionel.miquel46@gmail.com> | 2018-10-04 08:13:08 +0200 |
commit | 8fd35574400834517db2a51e92eba970f614843e (patch) | |
tree | efc032a6f130e80b0422159724654fadce6e99ce | |
parent | 0943dd142523b53e3748987fd16c77e6567c2fab (diff) | |
download | randopitons-8fd35574400834517db2a51e92eba970f614843e.tar.gz randopitons-8fd35574400834517db2a51e92eba970f614843e.zip |
On a encore plus nettoyé tout ce bazard, on va maintenant améliorer le sctrip
t pour le parsing des fichiers
-rw-r--r-- | init.py | 21 | ||||
-rw-r--r-- | inputs.py | 9 | ||||
-rw-r--r-- | mapsparsing.py | 48 | ||||
-rw-r--r-- | randoweb.py | 36 |
4 files changed, 51 insertions, 63 deletions
@@ -1,15 +1,28 @@ import os -from choices import mapfileinput +import inputs foldernames=["Cirque de Cilaos","Cirque de Mafate","Cirque de Salazie","Est","Nord","Ouest","Sud","Volcan","Ailleurs","All"] totalfolders=foldernames - +randonb=[] +basicfilename="" print "\n\nWelcome ! \nWith this script, you will be able to download gpx,trk and kml traces for hitchiking on the Reunion Isle." - +loginmail() +logipass() +filetype=mapfileinput() +if filetype==1: + basicfilename="f.gpx" +else if filetype==2: + basicfilename="f.trk" +else: + basicfilename="f.kml" + +payload = { + 'mail': MAIL, + 'password': PSW +} -mapfileinput() @@ -1,4 +1,5 @@ import colorcode +import getpass def mapfileinput(): maptype = 0 @@ -46,3 +47,11 @@ def regioninput(): print "\nPlease enter a number between 1 and 10." zone = 0 return zone + +def loginmail(): + MAIL=raw_input("Your email to log in to randopitons.re : ") + return MAIL + +def loginpass(): + PSW=getpass.getpass(prompt="Your password to log in to randopitons.re: ") + return PASS diff --git a/mapsparsing.py b/mapsparsing.py index 4fc1cc5..c0fcc91 100644 --- a/mapsparsing.py +++ b/mapsparsing.py @@ -1,45 +1,33 @@ import xml.etree.ElementTree as xmlp import re -def gpxparsing(): + +def mapparsing(filetype,basicfilename): try: - tree=xmlp.parse('f.gpx') + tree=xmlp.parse(basicfilename) root=tree.getroot() + filename=root[1][0].text+".gpx" - os.rename('f.gpx',filename) + + + os.rename(basicfilename,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') + os.remove(basicfilename) pass return filename - - -def kmlparsing(): - - try: - tree=xmlp.parse('f.kml') - root=tree.getroot() + + #kml 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() + #gpx 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 + + #trk + thefile=open("f.trk") + for i in range(3): + thefile.readline() + name=thefile.readline() + re.findall(r'\|(.*?)\|', filename) diff --git a/randoweb.py b/randoweb.py index c714a40..cb1b7c7 100644 --- a/randoweb.py +++ b/randoweb.py @@ -1,32 +1,21 @@ from requests import session -import getpass - -import os +import inputs from bs4 import BeautifulSoup as bs -def main(region,maptype): - MAIL=raw_input("Your email to log in to randopitons.re : ") - PSW=getpass.getpass(prompt="Your password to log in to randopitons.re: ") - - - payload = { - 'mail': MAIL, - 'password': PSW - } - with session() as c: try: post('https://randopitons.re/connexion', data=payload) + region = c.get('https://randopitons.re/randonnees/region/'+region) + wsite=bs(region) except SSLError, sslerr: 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) + - randonb=[] + for i in wsite.find_all('tr'): randonb.append(i.get("rid")) @@ -34,22 +23,11 @@ def main(region,maptype): for i in randonb: dwnld = c.get('https://randopitons.re/randonnee/'+i+'/trace/'+maptype) gudencoding=dwnld.text.encode('utf-8') + gpxf=open('f.gpx','a+') gpxf.write(gudencoding) gpxf.close() - 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 - - + print("FINISHED WRITING FILES") except OSError, e: print("Operating System error: {0}".format(e)) |