Last active
November 7, 2023 09:02
-
-
Save woctezuma/0d045dde3d4ca7ef5353890e6c84fbe5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# My Napkin API to get a dict mapping Steam appIDs to app names | |
# | |
# References: | |
# [1] API host: https://www.napkin.io/ | |
# [2] Documentation by SteamDB: https://steamapi.xpaw.me/#IStoreService/GetAppList | |
# [3] Personal API endpoint: cf. the title of this Github Gist | |
from napkin import response | |
import os | |
import requests | |
print('ok') | |
def download_data(num_apps=50000, last_appid=None): | |
url = 'https://api.steampowered.com/IStoreService/GetAppList/v1/' | |
payload = { | |
'access_token': os.getenv('access_token'), | |
'max_results': str(num_apps), | |
} | |
if last_appid is not None: | |
payload['last_appid'] = last_appid | |
r = requests.get(url, params=payload) | |
if r.ok: | |
data = r.json() | |
else: | |
data = {} | |
try: | |
d = data['response']['apps'] | |
except KeyError: | |
d = [] | |
try: | |
last_appid = data['response']['last_appid'] | |
except KeyError: | |
last_appid = None | |
return d, last_appid | |
d1, last_appid = download_data() | |
print(f'Data downloaded until appID = {last_appid}') | |
d2, last_appid = download_data(last_appid=last_appid) | |
print(f'Data downloaded until appID = {last_appid}') | |
app_list = d1 + d2 | |
expected_num_apps = len(app_list) | |
print(f'Expected #apps = {expected_num_apps}') | |
app_dict = { | |
app['appid']: app['name'] | |
for app in app_list | |
} | |
total_num_apps = len(app_dict) | |
print(f'Total #apps = {total_num_apps}') | |
response.status_code = 200 | |
response.body = app_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment