summaryrefslogtreecommitdiff
path: root/crawler.py
diff options
context:
space:
mode:
Diffstat (limited to 'crawler.py')
-rw-r--r--crawler.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/crawler.py b/crawler.py
index b68ec22..b188a86 100644
--- a/crawler.py
+++ b/crawler.py
@@ -33,11 +33,18 @@ class Crawler(object):
"Content-Encoding": "gzip"
}
try:
- async with session.get(self._apiurl + path, headers=headers,
- params=params) as response:
- assert response.status == 200
- return await response.json()
- except (aiohttp.errors.ClientResponseError, RuntimeError):
+ while True:
+ async with session.get(self._apiurl + path, headers=headers,
+ params=params) as response:
+ if response.status == 429:
+ logging.warning("hit by rate limit, retrying")
+ await asyncio.sleep(10)
+ continue
+ assert response.status == 200
+ return await response.json()
+ except (aiohttp.errors.ClientResponseError,
+ RuntimeError,
+ aiohttp.errors.ContentEncodingError):
logging.warning("error connecting to API, retrying")
return await self._req(session, path, params)
@@ -81,6 +88,10 @@ class Crawler(object):
data += res["data"] + res["included"]
+ if len(res["data"]) < 50:
+ # asked for 50, got less -> exhausted
+ break
+
if not forever:
break # stop after one iteration