-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_positions.py
68 lines (51 loc) · 2.35 KB
/
get_positions.py
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
from requests_html import HTMLSession
import json
gitana_url = "http://gitana-team.geovoile.com/tropheejulesverne/2020/tracker/?lg=fr"
sodebo_url = "https://sodebo-voile.geovoile.com/tropheejulesverne/2020/tracker/?lg=fr"
data = {}
# Gitana
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:82.0) Gecko/20100101 Firefox/82.0',
'Upgrade-Insecure-Requests': '1',
'If-None-Match': "637418997940064246",
'Host': "gitana-team.geovoile.com",
'Cookie': 'ASP.NET_SessionId=ilhxxwzt1k0cg2lxq2rigaes',
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
}
session = HTMLSession()
r = session.get(gitana_url, headers=headers)
r.html.render(timeout=10, sleep=2)
index = r.html.full_text.find("Situation")
coordonnees_gitana_raw = r.html.full_text[index:index + 50].split('\n')
gitana_lat_lon = []
for elt in coordonnees_gitana_raw:
if elt.find("°") != -1:
gitana_lat_lon.append(elt)
data['gitana'] = {}
data['gitana']['lat'] = gitana_lat_lon[0].replace('°', ',').replace('\'', ',').replace('.', ',')
data['gitana']['lng'] = gitana_lat_lon[1].replace('°', ',').replace('\'', ',').replace('.', ',')
data['gitana']['cap'] = int(gitana_lat_lon[2].replace(' °', ''))
r = session.get(sodebo_url, headers=headers)
r.html.render(timeout=10, sleep=2)
index = r.html.full_text.find("Situation")
coordonnees_sodebo_raw = r.html.full_text[index:index + 50].split('\n')
sodebo_lat_lon = []
for elt in coordonnees_sodebo_raw:
if elt.find("°") != -1:
sodebo_lat_lon.append(elt)
data['sodebo'] = {}
data['sodebo']['lat'] = sodebo_lat_lon[0].replace('°', ',').replace('\'', ',').replace('.', ',')
data['sodebo']['lng'] = sodebo_lat_lon[1].replace('°', ',').replace('\'', ',').replace('.', ',')
data['sodebo']['cap'] = int(sodebo_lat_lon[2].replace(' °', ''))
index = r.html.full_text.find("Position du")
index_end = r.html.full_text.find("FR")
timedate_str = r.html.full_text[index:index_end+2]
data['datetime'] = timedate_str
print(data)
json_data = json.dumps(data, indent=4)
json_file = open('./ultims_data.json', 'w')
json_file.write(json_data)
json_file.close()