Skip to content

Commit 856763c

Browse files
committed
Retry Plausible stats using backoff
1 parent f13328f commit 856763c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

generate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# "jinja2",
77
# "requests",
88
# "docutils",
9+
# "backoff",
910
# ]
1011
# ///
1112
import subprocess

visitors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import csv
22
import io
3-
import urllib
3+
import urllib.parse
44
import zipfile
55

6+
import backoff
67
from requests import Session
78

89

10+
@backoff.on_exception(backoff.expo, zipfile.BadZipFile, max_tries=5)
911
def get_number_of_visitors(language: str, requests: Session) -> int:
1012
params = urllib.parse.urlencode(
1113
{'filters': f'[["contains","event:page",["/{language}/"]]]', 'period': 'all'}
1214
)
1315
r = requests.get(
14-
f'https://plausible.io/docs.python.org/export?{params}', timeout=20
16+
f'https://plausible.io/docs.python.org/export?{params}', timeout=40
1517
)
1618
with (
1719
zipfile.ZipFile(io.BytesIO(r.content), 'r') as z,

0 commit comments

Comments
 (0)