aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--foldercreating.py34
-rw-r--r--main.py15
-rw-r--r--mapsparsing.py17
-rw-r--r--randoweb.py106
4 files changed, 111 insertions, 61 deletions
diff --git a/foldercreating.py b/foldercreating.py
index a4497d2..5a0d91d 100644
--- a/foldercreating.py
+++ b/foldercreating.py
@@ -9,7 +9,7 @@ import randoweb as rdo
thehome=os.path.expanduser("~")
defoldername="/Randopitons"
def_folder=thehome+defoldername
-
+a_folder=0
@@ -37,28 +37,42 @@ def mainfolder():
pass
except SyntaxError:
-
os.mkdir(def_folder)
except KeyboardInterrupt:
print e.sigkill
+ except:
+ raise
-def mkfolder(MAIL,PSW,regionnames,foldernames,maptype,ptr,choice,bfn):
+def mkfolder(MAIL,PSW,regionnames,foldernames,maptype,ptr,bfn):
try:
- os.mkdir(os.path.join(thehome,foldernames[ptr]))
- rdo.randoweb(MAIL,PSW,regionnames[ptr],filetype,bfn)
+ if a_folder==0:
+ os.mkdir(os.path.join(def_folder,foldernames[ptr]))
+ else:
+ os.mkdir(os.path.join(a_folder,foldernames[ptr]))
+ rdo.randoweb(MAIL,PSW,regionnames[ptr],maptype,bfn)
except OSError, er:
print e.os
print format(er)
def mkallfolder(MAIL,PSW,regionnames,foldernames,maptype,bfn):
- i=0
+ iii=0
+ a_str="str"
try:
- for foldernames in foldernames:
- os.mkdir(os.path.join(thehome,str(foldernames)))
- rdo.randoweb(MAIL,PSW,regionnames[i],maptype,bfn)
- i=i+1
+ for a_str in foldernames:
+ if a_folder==0:
+ os.mkdir(os.path.join(def_folder,a_str))
+ else:
+ os.mkdir(os.path.join(a_folder,a_str))
+
+
+ try:
+ print "on attaque par le "+regionnames[iii]
+ rdo.randoweb(MAIL,PSW,regionnames[iii],maptype,bfn)
+ except:
+ raise
+ iii=iii+1
#subprocess.call("rm -d "+fullpath)
print "All folders were created successfully"
except OSError, er:
diff --git a/main.py b/main.py
index fd462be..56f04d6 100644
--- a/main.py
+++ b/main.py
@@ -15,8 +15,11 @@ for i in range(9):
pass
import foldercreating as fdc
basicfilename=""
-randonb=[]
-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
+
+print clc.bold+"*************************************************************************************************************"
+print clc.bold+"* Welcome ! *"+clc.endc
+print clc.bold+"* With this script, you will be able to download gpx,trk and kml traces for hitchiking on the Reunion Isle. *"+clc.endc
+print clc.bold+"*************************************************************************************************************"
zonechoice=io.regioninput()
zoneptr=zonechoice-1
maptype=io.mapfileinput()
@@ -33,9 +36,11 @@ elif maptype==3:
basicfilename="f.kml"
fdc.mainfolder()
-fdc.mkfolder(MAIL,PSW,webregionnames,foldernames,maptype,zoneptr,basicfilename)
+if zonechoice == 10:
+ fdc.mkallfolder(MAIL,PSW,webregionnames,foldernames,maptype,basicfilename)
+else:
+ fdc.mkfolder(MAIL,PSW,webregionnames,foldernames,maptype,zoneptr,basicfilename)
+
-if zonechoice == 10:
- fdc.mkallfolder(MAIL,PSW,webregionnames,foldernames,maptype,zoneptr,basicfilename)
diff --git a/mapsparsing.py b/mapsparsing.py
index 7128f62..6caa37a 100644
--- a/mapsparsing.py
+++ b/mapsparsing.py
@@ -1,12 +1,12 @@
import xml.etree.ElementTree as xmlp
import re
-import errmsg as e
-
+import errmsg as reeee
+import os
def mapparsing(maptype,basicfilename):
try:
+ tree=xmlp.parse(basicfilename)
root=tree.getroot()
if maptype==1:
- tree=xmlp.parse(basicfilename)
filename=root[1][0].text+".gpx"
elif maptype==2:
thefile=open(basicfilename)
@@ -14,15 +14,14 @@ def mapparsing(maptype,basicfilename):
thefile.readline()
filename=re.findall(r'\|(.*?)\|', thefile.readline())[0]+".trk"
elif maptype==3:
- tree=xmlp.parse(basicfilename)
filename= root[0][10][1][0].text+".kml"
os.rename(basicfilename,filename)
except OSError, e:
- print e.os
- except xmlp.ParseError, e:
- print e.formaterr
- print format(e)
+ print reeee.os
+ except xmlp.ParseError, er:
+ print reeee.formaterr
+ print format(er)
os.remove(basicfilename)
pass
- return filename
+
diff --git a/randoweb.py b/randoweb.py
index 5955f14..3957ef1 100644
--- a/randoweb.py
+++ b/randoweb.py
@@ -1,14 +1,23 @@
+# -*- coding: utf-8 -*-
from requests import session
import inputs
from bs4 import BeautifulSoup as bs
import colorcode as clc
import errmsg as e
import mapsparsing as mpp
-
-
-
-
+randonb=[]
+a_str="eh"
+baseurl='https://randopitons.re/randonnee/'
+def filei(dwnld,bfn):
+ try:
+ f=open(bfn,'a+')
+ gudencoding=dwnld.text.encode('utf-8')
+ f.write(gudencoding)
+ f.close()
+ except:
+ raise
+
def randoweb(MAIL,PSW,region,maptype,bfn):
payload = {
'mail': MAIL,
@@ -18,39 +27,62 @@ def randoweb(MAIL,PSW,region,maptype,bfn):
with session() as c:
try:
- 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
-
- try:
- for i in randonb:
- dwnld="all the interwebz"
- if maptype==1:
- dwnld = c.get('https://randopitons.re/randonnee/'+i+'/trace/gpx')
- gpxf=open(bfn,'a+')
- elif maptype==2:
- dwnld = c.get('https://randopitons.re/randonnee/'+i+'/trace/kml')
- gpxf=open(bfn,'a+')
- else:
- dwnld = c.get('https://randopitons.re/randonnee/'+i+'/trace/trk')
- gpxf=open(bfn,'a+')
-
- gudencoding=dwnld.text.encode('utf-8')
- gpxf.write(gudencoding)
- gpxf.close()
+ c.post('https://randopitons.re/connexion', data=payload)
+ regionpage = c.get('https://randopitons.re/randonnees/region/'+region)
+ try:
+ wsite=bs(regionpage.text, "lxml")
+ print "Voici les donnees:"+regionpage.text
+ except:
+ raise
+ try:
+ for i in wsite.find_all('tr'):
+ randonb.append(i.get("rid"))
+ try:
+ randonb.pop(0)
+ print "POPPED"
+ except:
+ raise
+ print "Voici les numéros de randos:"
+ print randonb
+ except:
+ raise
- mpp.mapparsing(maptype,bfn)
- print("Finished writing files.")
- except OSError, er:
- print e.os
- print format(er)
-
-
+
+
+ try:
+ for i in randonb:
+ if maptype==1:
+ try:
+ dwnld = c.get(baseurl+i+'/trace/gpx')
+ except TypeError:
+ pass
+ except:
+ raise
+ filei(dwnld,bfn)
+ elif maptype==2:
+ try:
+ dwnld = c.get(baseurl+i+'/trace/kml')
+ except TypeError:
+ pass
+ except:
+ raise
+ filei(dwnld,bfn)
+ else:
+ try:
+ dwnld = c.get(baseurl+i+'/trace/trk')
+ except TypeError:
+ pass
+ except:
+ raise
+ filei(dwnld,bfn)
+ except:
+ raise
+ try:
+ mpp.mapparsing(maptype,bfn)
+ except:
+ raise
+ print("Finished writing file.")
+ except :
+ raise
-#print(response.headers)
-#print(response.text)