aboutsummaryrefslogtreecommitdiff
path: root/randoweb.py
blob: 57fd7f331b425219ebf24423dc13dc34058a14c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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