Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import sys
from time import sleep
import requests
from requests.utils import parse_header_links
import datetime
from pymongo import MongoClient
from concurrent.futures import ThreadPoolExecutor, as_completed
Expand Down Expand Up @@ -130,15 +131,19 @@ def fetch_window(
break

# look at Link header for next cursor or end
link = r.headers.get("Link", "")
if 'results="false"' in link:
break
# naive parse of cursor—tweak to your needs
try:
cursor = link.split("cursor=")[-1].split('"')[1]
except Exception:
link_header = r.headers.get("Link", "")
next_link = None
if link_header:
for link in parse_header_links(link_header):
if link.get("rel") == "next":
next_link = link
break

if not next_link or next_link.get("results") == "false":
break

cursor = next_link.get("cursor")

return new_records, total_records


Expand Down