From 6f8af4d10fa7e0d4a7bd4a6e5c958527e8cd5ed7 Mon Sep 17 00:00:00 2001 From: Lionel Date: Wed, 31 Oct 2018 12:20:09 +0100 Subject: Cleaning up the repo --- .README.md.swp | Bin 12288 -> 0 bytes .randopitons.sh.swp | Bin 16384 -> 0 bytes README.md | 1 + prototyping/__init__.py | 0 prototyping/colorcode.py | 22 ------- prototyping/errmsg.py | 7 --- prototyping/foldercreating.py | 82 -------------------------- prototyping/inputs.py | 69 ---------------------- prototyping/main.py | 46 --------------- prototyping/mapsparsing.py | 27 --------- prototyping/randoweb.py | 133 ------------------------------------------ randopitons.sh | 8 +-- 12 files changed, 5 insertions(+), 390 deletions(-) delete mode 100644 .README.md.swp delete mode 100644 .randopitons.sh.swp delete mode 100644 prototyping/__init__.py delete mode 100644 prototyping/colorcode.py delete mode 100644 prototyping/errmsg.py delete mode 100644 prototyping/foldercreating.py delete mode 100644 prototyping/inputs.py delete mode 100644 prototyping/main.py delete mode 100644 prototyping/mapsparsing.py delete mode 100644 prototyping/randoweb.py (limited to ':') diff --git a/.README.md.swp b/.README.md.swp deleted file mode 100644 index aab92eb..0000000 Binary files a/.README.md.swp and /dev/null differ diff --git a/.randopitons.sh.swp b/.randopitons.sh.swp deleted file mode 100644 index 0b01a5a..0000000 Binary files a/.randopitons.sh.swp and /dev/null differ diff --git a/README.md b/README.md index 0731c3e..523b798 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Hello ! Here's a bash script for downloading hitchiking files from [https://randopitons.re](https://randopitons.re) You will need to make an account on the website before using the script (as these credentials are needed). +Work is still on progress. ## Installation If you have git installed on your computer, you can clone it by doing: diff --git a/prototyping/__init__.py b/prototyping/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/prototyping/colorcode.py b/prototyping/colorcode.py deleted file mode 100644 index e120109..0000000 --- a/prototyping/colorcode.py +++ /dev/null @@ -1,22 +0,0 @@ -# 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 deleted file mode 100644 index 8e67d42..0000000 --- a/prototyping/errmsg.py +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 489d588..0000000 --- a/prototyping/foldercreating.py +++ /dev/null @@ -1,82 +0,0 @@ -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 deleted file mode 100644 index 3b47bef..0000000 --- a/prototyping/inputs.py +++ /dev/null @@ -1,69 +0,0 @@ -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 deleted file mode 100644 index 56f04d6..0000000 --- a/prototyping/main.py +++ /dev/null @@ -1,46 +0,0 @@ -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 deleted file mode 100644 index 6caa37a..0000000 --- a/prototyping/mapsparsing.py +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index 57fd7f3..0000000 --- a/prototyping/randoweb.py +++ /dev/null @@ -1,133 +0,0 @@ -# -*- 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 - - diff --git a/randopitons.sh b/randopitons.sh index 3b58664..711943d 100644 --- a/randopitons.sh +++ b/randopitons.sh @@ -20,8 +20,8 @@ IFS=$'\n' _tellusage() { - echo -e "${BLD}PURPOSE:${RS} With this script, you will be able to download gpx,trk and kml files for hitchiking on the Reunion Isle.\n -${BLD}USAGE$RS: . ./randopitons.sh option1 option2 option3 + echo -e "PURPOSE:${RS} With this script, you will be able to download gpx,trk and kml files for hitchiking on the Reunion Isle.\n +USAGE$RS: . ./randopitons.sh option1 option2 option3 The following options are mandatory: --username/-u \"your-username-or-email@randopitons.re\": After that, you will be prompted for your password (it won't display it as you type so don't worry, it's for protecting you from curious peoples looking at you screen (a.k.a shouldersurfing). @@ -99,7 +99,7 @@ while [ "$1" != "" ]; do while [ $MAPTYPE != "gpx" -a $MAPTYPE != "trk" -a $MAPTYPE != "kml" ] do echo -e "\nMaptype supplied is not correct" - echo -e "Which map filetype you want to set : ${BLD}gpx(default),trk or kml ?$RS" + echo -e "Which map filetype you want to set : gpx(default),trk or kml ?$RS" read -N 3 MAPTYPE done echo -e $HC$FGRN"\nThe $MAPTYPE maptype is a valid choice !"$RS @@ -127,7 +127,7 @@ while [ "$1" != "" ]; do done ;; -a | --all ) - echo -e "\nThis will download all the hitchiking routes from all regions.\nIf no maptype is specified (with -mp or --maptype), it will default to .gpx filetype.\n${BLD}Pausing for 5 seconds before launching it.$RS" + echo -e "\nThis will download all the hitchiking routes from all regions.\nIf no maptype is specified (with -mp or --maptype), it will default to .gpx filetype.\nPausing for 5 seconds before launching it.$RS" sleep 5 while read linefromfile; do mkdir "${linefromfile}" -- cgit v1.2.3-70-g09d2