-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (37 loc) · 1.1 KB
/
main.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
import datetime
import csv
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
def requests_retry_session(
retries=5,
backoff_factor=1,
status_forcelist=[401, 402, 403, 500, 502, 504],
session=None,
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session
r = requests_retry_session().get("https://webconf.numerique.gouv.fr/stats/homePage", verify=False)
r.raise_for_status()
data = r.json()
date = datetime.datetime.utcnow().isoformat()
hourly_data = {
"date": date,
"nb_conferences": data["conf"],
"nb_participants": data["part"],
}
with open("data/data.csv", "a") as f:
writer = csv.DictWriter(f, hourly_data, lineterminator="\n")
if f.tell() == 0:
writer.writeheader()
writer.writerow(hourly_data)