aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLionel <lionel.miquel46@gmail.com>2018-10-16 15:34:08 +0200
committerLionel <lionel.miquel46@gmail.com>2018-10-16 15:34:08 +0200
commit6bf912ba61aee249c344ebbd160df0280748fa9e (patch)
treecbe90be13557052d7abd24fb53ef70530d8c0070
parentba91e0892c8a57a13bacb4d5d577940fc2793d20 (diff)
downloadrandopitons-6bf912ba61aee249c344ebbd160df0280748fa9e.tar.gz
randopitons-6bf912ba61aee249c344ebbd160df0280748fa9e.zip
On avance ça va. Création de errmsg.py qui regroupe les messages d'erreurs qui sont et (seront) récurrents
-rw-r--r--colorcode.py43
-rw-r--r--errmsg.py7
-rw-r--r--foldercreating.py88
-rw-r--r--inputs.py15
-rw-r--r--main.py15
-rw-r--r--mapsparsing.py37
-rw-r--r--randoweb.py16
7 files changed, 110 insertions, 111 deletions
diff --git a/colorcode.py b/colorcode.py
index b8debd5..e120109 100644
--- a/colorcode.py
+++ b/colorcode.py
@@ -1,27 +1,22 @@
+# coding: utf-8
#Simplified color codes here for error/warning/ok and the such.. messages
-
-#def endcolor(s):
-# print s+'\033[0m'
-#
-#def bold(s):
-# endcolor('\033[1m'+s)
-#
-#def header(s):
-# endcolor('\033[95m'+s)
-#
-#def okblue(s):
-# print '\033[94m'+endcolor(s)
-#
-#def okgreen(s):
-# print '\033[92m'+endcolor(s)
-#
-#def warning(s):
-# print '\033[93m'+endcolor(s)
-#
-#def fail(s):
-# print '\033[91m'+endcolor(s)
#
-#def underline(s):
-# print '\033[4m'+endcolor(s)
+#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'
-#bold("fancy shit man")
+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/errmsg.py b/errmsg.py
new file mode 100644
index 0000000..25e0641
--- /dev/null
+++ b/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/foldercreating.py b/foldercreating.py
index a95c169..a6fa34f 100644
--- a/foldercreating.py
+++ b/foldercreating.py
@@ -1,61 +1,51 @@
import subprocess
import os
import time
-
+import colorcode as clc
+import errmsg as e
#global foldernames
-#(foldernames[0].split(' ')[0]+"-"+foldernames[0].split(' ')[2]).lower() => cirque-cilaos . ce formating sera pratique pour le site web
+#(foldernames[0].split(' ')[0]+"-"+foldernames[0].split(' ')[2]).lower() => cirque-cilaos . ce formating sera pratique lors de la récupération sur site web
thehome=os.path.expanduser("~")
thefolder="/Randopitons"
default_folder=thehome+thefolder
-##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+" ..."
+def mkfolder(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 e.os
+ print format(e)
+
+def mainfolder():
+ 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"
+ 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 e.direxist
+ else:
+ print e.os
+ print format(e)
+ pass
+ except SyntaxError:
+ print "\nCreating default folder "+default_folder+" ..."
os.mkdir(default_folder)
-
-
-
-
-
- #================DECLARING FOLDERNAMES==============
-
-
-
-
-print "Program ended."
+#print "Program ended."
diff --git a/inputs.py b/inputs.py
index 9185cbc..df067d2 100644
--- a/inputs.py
+++ b/inputs.py
@@ -1,10 +1,11 @@
-import colorcode
import getpass
+import colorcode as clc
+import errmsg as e
def mapfileinput():
maptype = 0
- print """\n Which map file extension you would want to download ?
- 1. gpx (GPS Exchange Format)
+ 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"""
@@ -13,7 +14,7 @@ def mapfileinput():
maptype = input("You must enter a number between 1 and 3. Your choice ? ")
int(maptype)
except (KeyboardInterrupt, SystemExit):
- print WARNING+"\n\nProcess interrupted by CTRL+C or system."+ENDC
+ print e.sigkill
exit()
return maptype
@@ -21,8 +22,8 @@ def mapfileinput():
def regioninput():
zone = 0
- print """\n Which zone you would want to download ?
- 1. Cirque de Cilaos (Cilaos' Circus)
+ 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)
@@ -38,7 +39,7 @@ def regioninput():
zone = input("You must enter a number between 1 and 10. Your zone [Default is \"All\"]: ")
int(zone)
except (KeyboardInterrupt, SystemExit):
- print WARNING+"\n\nProcess interrupted by CTRL+C or system."+ENDC
+ 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 "+BOLD+"CTRL+C"+ENDC)
diff --git a/main.py b/main.py
index 6c6e4d8..3a85d8b 100644
--- a/main.py
+++ b/main.py
@@ -1,10 +1,14 @@
import os
import inputs
+import mapsparsing
+import colorcode as clc
+import foldercreating as fdc
+
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."
+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
loginmail()
logipass()
@@ -15,14 +19,19 @@ if filetype==1:
basicfilename="f.gpx"
elif filetype==2:
basicfilename="f.trk"
-else:
+else filetype==3:
basicfilename="f.kml"
-
+
+mapparsing(filetype,basicfilename)
+
+
payload = {
'mail': MAIL,
'password': PSW
}
+randoweb()
+
diff --git a/mapsparsing.py b/mapsparsing.py
index c0fcc91..7fb6edd 100644
--- a/mapsparsing.py
+++ b/mapsparsing.py
@@ -1,33 +1,28 @@
import xml.etree.ElementTree as xmlp
import re
-
+import errmsg as e
def mapparsing(filetype,basicfilename):
try:
- tree=xmlp.parse(basicfilename)
root=tree.getroot()
-
- filename=root[1][0].text+".gpx"
-
-
+ if filetype==1:
+ tree=xmlp.parse(basicfilename)
+ filename=root[1][0].text+".gpx"
+ else filetype==2:
+ tree=xmlp.parse(basicfilename)
+ filename= root[0][10][1][0].text+".kml"
+ elif filetype==3:
+ thefile=open(basicfilename)
+ for i in range(3):
+ thefile.readline()
+ filename=re.findall(r'\|(.*?)\|', thefile.readline())[0]
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))
+ print e.os
+ except xml.etree.ElementTree.ParseError, e:
+ print e.formaterr
+ print format(e)
os.remove(basicfilename)
pass
return filename
- #kml
- filename= root[0][10][1][0].text+".kml"
-
- #gpx
- filename=root[1][0].text+".gpx"
-
- #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 cb1b7c7..6bc18bb 100644
--- a/randoweb.py
+++ b/randoweb.py
@@ -1,17 +1,18 @@
from requests import session
import inputs
from bs4 import BeautifulSoup as bs
+import colorcode as clc
+import errmsg as e
-
-
+def randoweb():
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."
+ print e.sslerr
@@ -28,12 +29,13 @@ from bs4 import BeautifulSoup as bs
gpxf.write(gudencoding)
gpxf.close()
- print("FINISHED WRITING FILES")
+ print("Finished writing files.")
except OSError, e:
- print("Operating System error: {0}".format(e))
+ print e.os
+ print format(e)
- print(response.headers)
-print(response.text)
+#print(response.headers)
+#print(response.text)