aboutsummaryrefslogtreecommitdiff
path: root/randoweb.py
blob: 3957ef1d0da12b593131d4bd79e55f3322d2a16f (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
# -*- coding: utf-8 -*-
from requests import session
import inputs
from bs4 import BeautifulSoup as bs
import colorcode as clc
import errmsg as e
import mapsparsing as mpp
randonb=[]
a_str="eh"
baseurl='https://randopitons.re/randonnee/'
    
def filei(dwnld,bfn):
    try:
        f=open(bfn,'a+')
        gudencoding=dwnld.text.encode('utf-8')
        f.write(gudencoding)
        f.close()
    except:
        raise

def randoweb(MAIL,PSW,region,maptype,bfn):
    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:
                            dwnld = c.get(baseurl+i+'/trace/gpx')
                        except TypeError:
                            pass
                        except:
                            raise
                        filei(dwnld,bfn)
                    elif maptype==2:
                        try:
                            dwnld = c.get(baseurl+i+'/trace/kml')
                        except TypeError:
                            pass
                        except:
                            raise
                        filei(dwnld,bfn)
                    else:
                        try:
                            dwnld = c.get(baseurl+i+'/trace/trk')
                        except TypeError:
                            pass
                        except:
                            raise
                        filei(dwnld,bfn)
            except:
                raise   
            try:
                mpp.mapparsing(maptype,bfn)
            except:
                raise
            print("Finished writing file.")
        except :
            raise