Last active
May 4, 2024 21:06
-
-
Save woctezuma/10b9b14c76644978576ee0b043dc53ed to your computer and use it in GitHub Desktop.
Fetch a user's libary from EGS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from pathlib import Path | |
import requests | |
BASE_URL = ( | |
"https://library-service.live.use1a.on.epicgames.com/library/api/public/items" | |
) | |
STATIC_PARAMS = "includeMetadata=true" | |
OUTPUT_FNAME = "library-items.json" | |
SECRET_TOKEN = "eg1~XXX" | |
HEADERS = {"Authorization": f"Bearer {SECRET_TOKEN}"} | |
cursor = None | |
data = [] | |
while True: | |
dynamic_params = f"&cursor={cursor}" if cursor else "" | |
url = f"{BASE_URL}?{STATIC_PARAMS}{dynamic_params}" | |
print(url) | |
r = requests.get(url, headers=HEADERS, timeout=10) | |
if r.ok: | |
d = r.json() | |
data += d["records"] | |
meta_data = d["responseMetadata"] | |
try: | |
new_cursor = meta_data["nextCursor"] | |
except KeyError: | |
print(meta_data) | |
break | |
cursor = new_cursor | |
else: | |
print(r.status_code) | |
break | |
with Path(OUTPUT_FNAME).open("w", encoding="utf8") as f: | |
json.dump(data, f, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment