Skip to content

Instantly share code, notes, and snippets.

@woctezuma
Last active November 7, 2023 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woctezuma/0d045dde3d4ca7ef5353890e6c84fbe5 to your computer and use it in GitHub Desktop.
Save woctezuma/0d045dde3d4ca7ef5353890e6c84fbe5 to your computer and use it in GitHub Desktop.
# 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