aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--posttest.py59
-rw-r--r--randopitonreturn.py131
-rw-r--r--randopitonstest.py55
3 files changed, 245 insertions, 0 deletions
diff --git a/posttest.py b/posttest.py
new file mode 100644
index 0000000..0ebd49b
--- /dev/null
+++ b/posttest.py
@@ -0,0 +1,59 @@
+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 : ")
+
+
+ payload = {
+ 'mail': MAIL,
+ 'password': PSW
+ }
+
+ with session() as c:
+ try:
+ post('https://randopitons.re/connexion', data=payload)
+ except SSLError, sslerr:
+ print "Erreur de certificat SSL"
+
+ 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"))
+
+ try:
+ 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 occuredwith the formating:{0}".format(e))
+ os.remove('f.gpx')
+ pass
+
+
+ print("FINISHED WRITING FILES")
+ except OSError, e:
+ print("Operating System error: {0}".format(e))
+
+
+
+ print(response.headers)
+print(response.text)
+
diff --git a/randopitonreturn.py b/randopitonreturn.py
new file mode 100644
index 0000000..6ecf7f8
--- /dev/null
+++ b/randopitonreturn.py
@@ -0,0 +1,131 @@
+import subprocess
+import os
+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
+
+
+##def dlmap(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 colrs.WARNING+("Operating System error: {0}".format(e))+colrs.ENDC
+
+
+print "\n\nWelcome ! \nWith this script, you will be able to download gpx,trk and kml traces for hitchiking on the Reunion Isle."
+
+#=================CREATING MAIN FOLDER AND OTHERS OR ALL===================
+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"
+ #dlmap(maptype,choice)
+except OSError, e:
+ #errors out if folder exists else print the error (can be permissions or anything else)
+ if e.errno == os.errno.EEXIST:
+ print colrs.WARNING+("The folder already exists !")+colrs.ENDC
+ else:
+ print colrs.FAIL+("Operating System error: {0}".format(e))+colrs.ENDC
+ pass
+except SyntaxError:
+ print "\nCreating default folder "+default_folder+" ..."
+ os.mkdir(default_folder)
+
+
+
+
+
+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."
diff --git a/randopitonstest.py b/randopitonstest.py
new file mode 100644
index 0000000..699803d
--- /dev/null
+++ b/randopitonstest.py
@@ -0,0 +1,55 @@
+import requests
+USERNAME = "lionel.miquel46@gmail.com"
+PASSWORD = "VEobWylvUdToab8"
+LOGINURL = "https://randopitons.re"
+DATAURL = "https://randopitons.re/randonnees/region/cirque-cilaos"
+session = requests.session()
+req_headers = {
+'POST /connexion HTTP/1.1'
+
+'Host: randopitons.re'
+
+'Connection: keep-alive'
+
+'Content-Length: 57'
+
+'Cache-Control: max-age=0'
+
+'Origin: https://randopitons.re'
+
+'Upgrade-Insecure-Requests: 1'
+
+'Content-Type: application/x-www-form-urlencoded'
+
+'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/68.0.3440.106 Chrome/68.0.3440.106 Safari/537.36'
+
+'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
+
+'Referer: https://randopitons.re/connexion'
+
+'Accept-Encoding: gzip, deflate, br'
+
+'Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7'
+
+'Cookie: randop_sess=ac5cd2e84ea151bd16bf787ea46f8c95ef867684"'
+}
+
+formdata = {
+ 'UserName': USERNAME,
+ 'Password': PASSWORD,
+ 'LoginButton' : 'Login'
+ }
+
+ # Authenticate
+r = session.post(LOGINURL, data=formdata, headers=req_headers, allow_redirects=True)
+print (r.headers)
+print (r.status_code)
+print (r.text)
+
+ # Read data
+r2 = session.get(DATAURL)
+print ("___________DATA____________")
+print (r2.headers)
+print (r2.status_code)
+print (r2.text)
+