aboutsummaryrefslogtreecommitdiff
path: root/prototyping
diff options
context:
space:
mode:
authorLionel <lionel.miquel46@gmail.com>2019-02-02 20:19:16 +0100
committerLionel <lionel.miquel46@gmail.com>2019-02-02 20:19:16 +0100
commit9ae6167d9b7ce53a273c46cf96cc73aaefb167f9 (patch)
tree98bc395eea7f574ce78193b849b2a881a19b6c33 /prototyping
parentf86db56f16896ef59be270526c090893809beae4 (diff)
downloadrandopitons-9ae6167d9b7ce53a273c46cf96cc73aaefb167f9.tar.gz
randopitons-9ae6167d9b7ce53a273c46cf96cc73aaefb167f9.zip
Deleted _config.yml, no use for it now
Diffstat (limited to 'prototyping')
-rwxr-xr-xprototyping/__init__.py0
-rwxr-xr-xprototyping/colorcode.py22
-rwxr-xr-xprototyping/errmsg.py7
-rwxr-xr-xprototyping/foldercreating.py82
-rwxr-xr-xprototyping/inputs.py69
-rwxr-xr-xprototyping/main.py46
-rwxr-xr-xprototyping/mapsparsing.py27
-rwxr-xr-xprototyping/randoweb.py133
8 files changed, 386 insertions, 0 deletions
diff --git a/prototyping/__init__.py b/prototyping/__init__.py
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/prototyping/__init__.py
diff --git a/prototyping/colorcode.py b/prototyping/colorcode.py
new file mode 100755
index 0000000..e120109
--- /dev/null
+++ b/prototyping/colorcode.py
@@ -0,0 +1,22 @@
+# coding: utf-8
+#Simplified color codes here for error/warning/ok and the such.. messages
+#
+#class Colorcode:
+# def __init__(self):
+# self.endcolor='\033[0m'
+# self.bold='\033[1m'
+# self.header='\033[95m'
+# self.okblue='\033[94m'
+# self.okgreen='\033[92m'
+# self.warn='\033[93m'
+# self.fail='\033[91m'
+# self.underline='\033[4m'
+
+endc='\033[0m'
+bold='\033[1m'
+head='\033[95m'
+okblue='\033[94m'
+okgreen='\033[92m'
+warn='\033[93m'
+fail='\033[91m'
+underline='\033[4m'
diff --git a/prototyping/errmsg.py b/prototyping/errmsg.py
new file mode 100755
index 0000000..8e67d42
--- /dev/null
+++ b/prototyping/errmsg.py
@@ -0,0 +1,7 @@
+import colorcode as clc
+os=clc.fail+"Operating System error:"+clc.endc
+direxist=clc.warn+clc.bold+"The folder already exists !"+clc.endc
+formaterr=clc.fail+"Something occured with the formating. File is not retrievable, passing on next download."+clc.endc
+sslerr=clc.fail+clc.bold+"SSL Certificate Error. Please check the time on your computer, adjust it accordingly, or wait a bit before retrying the downloads."+clc.endc
+sigkill=clc.fail+"\n\nProcess interrupted by CTRL+C or system."+clc.endc
+"\n\nProcess interrupted by CTRL+C or system."
diff --git a/prototyping/foldercreating.py b/prototyping/foldercreating.py
new file mode 100755
index 0000000..489d588
--- /dev/null
+++ b/prototyping/foldercreating.py
@@ -0,0 +1,82 @@
+import subprocess
+import os
+import time
+import colorcode as clc
+import errmsg as e
+import randoweb as rdo
+#global foldernames
+
+thehome=os.path.expanduser("~")
+defoldername="/Randopitons"
+def_folder=thehome+defoldername
+a_folder=0
+
+
+
+
+def defolder():
+ try:
+ print "\nCreating default folder "+def_folder+" ..."
+ os.mkdir(def_folder)
+ except OSError,er:
+ print e.os
+ print format(er)
+
+def mainfolder():
+ try:
+ a_folder=input("\n\nWhich folder would you want to download the files to [Default to home directory "+def_folder+"]")
+ os.mkdir(a_folder)
+ print "Folder "+a_folder+" was created successfully"
+ except OSError, er:
+ #errors out if folder exists else print the error (can be permissions or anything else)
+ if e.errno != os.errno.EEXIST:
+ raise
+ else:
+ print e.os
+ print format(er)
+ pass
+
+ except SyntaxError:
+ os.mkdir(def_folder)
+ except KeyboardInterrupt:
+ print e.sigkill
+ except:
+ raise
+
+def mkfolder(MAIL,PSW,regionnames,foldernames,maptype,ptr,bfn):
+
+ try:
+ if a_folder==0:
+ os.mkdir(os.path.join(def_folder,foldernames[ptr]))
+ else:
+ os.mkdir(os.path.join(a_folder,foldernames[ptr]))
+ #rdo.testalakon()
+ rdo.randoweb(MAIL,PSW,regionnames[ptr],maptype,bfn,def_folder+a_str)
+ except OSError, er:
+ print e.os
+ print format(er)
+
+
+def mkallfolder(MAIL,PSW,regionnames,foldernames,maptype,bfn):
+ iii=0
+ a_str="str"
+ try:
+ 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,def_folder+a_str)
+ except:
+ raise
+ iii=iii+1
+ #subprocess.call("rm -d "+fullpath)
+ print "All folders were created successfully"
+ except OSError, er:
+ print e.os
+ print format(er)
+
diff --git a/prototyping/inputs.py b/prototyping/inputs.py
new file mode 100755
index 0000000..3b47bef
--- /dev/null
+++ b/prototyping/inputs.py
@@ -0,0 +1,69 @@
+import getpass
+import colorcode as clc
+import errmsg as e
+
+
+def mapfileinput():
+ maptype = 0
+ print clc.bold+"\n Which map file extension you would want to download ?"+clc.endc
+ print """
+ 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 e.sigkill
+ exit()
+ except SyntaxError:
+ print "Defaulting to gpx. If this isn't what you wanted, you can always interrupt the script by pressing "+clc.bold+clc.okblue+"CTRL+C"+clc.endc
+ maptype=1
+ return maptype
+
+
+def regioninput():
+ zone = 0
+ print clc.bold+"\n Which zone you would want to download ?"+clc.endc
+ print """
+ 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 e.sigkill
+ exit()
+ except SyntaxError:
+ print("\nDefaulting to All. If this isn't what you wanted, you can always interrupt the script by pressing "+clc.bold+clc.okblue+"CTRL+C"+clc.endc)
+ zone = 10;
+ except NameError:
+ print "\nPlease enter a number between 1 and 10."
+ zone = 0
+ return zone
+
+def loginmail():
+ try:
+ MAIL=raw_input("Your email to log in to randopitons.re : ")
+ except KeyboardInterrupt:
+ print e.sigkill
+ return MAIL
+
+def loginpass():
+ try:
+ PSW=getpass.getpass(prompt="Your password to log in to randopitons.re: ")
+ except KeyboardInterrupt:
+ print e.sigkill
+ return PSW
diff --git a/prototyping/main.py b/prototyping/main.py
new file mode 100755
index 0000000..56f04d6
--- /dev/null
+++ b/prototyping/main.py
@@ -0,0 +1,46 @@
+import os
+import inputs as io
+
+import colorcode as clc
+foldernames=["Cirque de Cilaos","Cirque de Mafate","Cirque de Salazie","Est","Nord","Ouest","Sud","Volcan","Ailleurs","All"]
+webregionnames=[]
+for i in range(9):
+ try:
+ leftside=foldernames[i].split(' ')[0].lower()+"-"
+ rightside=foldernames[i].split(' ')[2].lower()
+ webregionnames.append(leftside+rightside)
+ except IndexError,ierr:
+ oneside=foldernames[i].split(' ')[0].lower()
+ webregionnames.append(oneside)
+ pass
+import foldercreating as fdc
+basicfilename=""
+
+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()
+MAIL=io.loginmail()
+PSW=io.loginpass()
+
+
+
+if maptype==1:
+ basicfilename="f.gpx"
+elif maptype==2:
+ basicfilename="f.trk"
+elif maptype==3:
+ basicfilename="f.kml"
+
+fdc.mainfolder()
+if zonechoice == 10:
+ fdc.mkallfolder(MAIL,PSW,webregionnames,foldernames,maptype,basicfilename)
+else:
+ fdc.mkfolder(MAIL,PSW,webregionnames,foldernames,maptype,zoneptr,basicfilename)
+
+
+
+
diff --git a/prototyping/mapsparsing.py b/prototyping/mapsparsing.py
new file mode 100755
index 0000000..6caa37a
--- /dev/null
+++ b/prototyping/mapsparsing.py
@@ -0,0 +1,27 @@
+import xml.etree.ElementTree as xmlp
+import re
+import errmsg as reeee
+import os
+def mapparsing(maptype,basicfilename):
+ try:
+ tree=xmlp.parse(basicfilename)
+ root=tree.getroot()
+ if maptype==1:
+ filename=root[1][0].text+".gpx"
+ elif maptype==2:
+ thefile=open(basicfilename)
+ for i in range(3):
+ thefile.readline()
+ filename=re.findall(r'\|(.*?)\|', thefile.readline())[0]+".trk"
+ elif maptype==3:
+ filename= root[0][10][1][0].text+".kml"
+ os.rename(basicfilename,filename)
+ except OSError, e:
+ print reeee.os
+ except xmlp.ParseError, er:
+ print reeee.formaterr
+ print format(er)
+ os.remove(basicfilename)
+ pass
+
+
diff --git a/prototyping/randoweb.py b/prototyping/randoweb.py
new file mode 100755
index 0000000..57fd7f3
--- /dev/null
+++ b/prototyping/randoweb.py
@@ -0,0 +1,133 @@
+# -*- coding: utf-8 -*-
+from requests import session
+import inputs
+from bs4 import BeautifulSoup as bs
+import colorcode as clc
+import errmsg as e
+import os
+import mapsparsing as mpp
+randonb=[]
+a_str="eh"
+baseurl='https://randopitons.re/randonnee/'
+
+def filei(dwnld,fpath):
+ try:
+ f=open(fpath,'a+')
+ gudencoding=dwnld.text.encode('utf-8')
+ f.write(gudencoding)
+ f.close()
+ except:
+ raise
+
+
+
+def testalakon():
+ payload = {
+ 'mail': 'lionel.miquel46@gmail.com',
+ 'password': 'VEobWylvUdToab8'
+ }
+ with session() as c:
+ try:
+ c.post('https://randopitons.re/connexion', data=payload)
+ regionpage = c.get('https://randopitons.re/randonnees/region/cirque-cilaos')
+ 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
+ try:
+ for i in randonb:
+ print clc.okgreen+"Maybe downloading "+baseurl+i+'/trace/gpx'
+ try:
+ dwnld = c.get(baseurl+i+'/trace/gpx')
+ except:
+ raise
+ filei(dwnld,'/home/lili/Randopitons/Cirque de Cilaos/f-'+i+'.gpx')
+ except:
+ raise
+ except:
+ raise
+ except:
+ raise
+
+def randoweb(MAIL,PSW,region,maptype,bfn,folderpath):
+ payload = {
+ 'mail': MAIL,
+ 'password': PSW
+ }
+
+ with session() as c:
+
+ try:
+ 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
+
+
+
+ try:
+ for i in randonb:
+ if maptype==1:
+ try:
+ print clc.okgreen+"Maybe downloading "+baseurl+i+'/trace/gpx'
+ dwnld = c.get(baseurl+i+'/trace/gpx')
+ except TypeError:
+ pass
+ except:
+ raise
+ filei(dwnld,folderpath+bfn)
+ elif maptype==2:
+ try:
+ print clc.okgreen+"Maybe downloading "+baseurl+i+'/trace/trk'
+ dwnld = c.get(baseurl+i+'/trace/trk')
+ except TypeError:
+ pass
+ except:
+ raise
+ filei(dwnld,folderpath+bfn)
+ else:
+ try:
+ print clc.okgreen+"Maybe downloading "+baseurl+i+'/trace/kml'
+ dwnld = c.get(baseurl+i+'/trace/kml')
+ except TypeError:
+ pass
+ except:
+ raise
+ filei(dwnld,folderpath+bfn)
+ except:
+ raise
+ try:
+ mpp.mapparsing(maptype,folderpath+bfn)
+ except:
+ raise
+ print("Finished writing file.")
+ except :
+ raise
+
+