Skip to content

Commit

Permalink
feat: add id_title_connector.SteamService
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabing010102 committed Dec 7, 2024
1 parent eab3f57 commit a6655bd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/id_title_connector/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import json

from module.SteamService import SteamService

if __name__ == '__main__':
steam_service = SteamService('C4C6CD52896D408FED14EA3564D0E59E')
app_list = steam_service.get_app_list()
with open('app_list.json', 'w', encoding='utf8') as f:
f.writelines(json.dumps(app_list, ensure_ascii=False, indent=2))
58 changes: 58 additions & 0 deletions scripts/id_title_connector/module/SteamService.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import time

import requests


class SteamService:
def __init__(self, webapi_key: str, request_interval: int = 10):
self.webapi_key = webapi_key
self.request_interval = request_interval

def get_app_list(self) -> dict[int, list[str]]:
apps = {}
self._i_store_service_get_app_list_v1(apps, 'schinese')
self._i_store_service_get_app_list_v1(apps, 'tchinese')
self._i_store_service_get_app_list_v1(apps, 'english')
self._i_store_service_get_app_list_v1(apps, 'japanese')
return apps

def _i_store_service_get_app_list_v1(self, apps: dict[int, list[str]]
, language: str) -> None:
last_appid = 0
while True:
try:
url = "https://api.steampowered.com/IStoreService/GetAppList/v1/"
params = {
'key': self.webapi_key,
# 'if_modified_since': 0,
'have_description_language': language,
'include_games': 'true',
'include_dlc': 'true',
'include_software': 'true',
'include_videos': 'false',
'include_hardware': 'false',
'last_appid': last_appid,
'max_results': 50000
}
response = requests.get(url, params=params).json()['response']

for app in response['apps']:
if app['appid'] not in apps:
apps[app['appid']] = []
if app['name'] not in apps[app['appid']]:
apps[app['appid']].append(app['name'])

if 'have_more_results' not in response or not response['have_more_results']:
print(f"IStoreService/GetAppList/v1: l: {language}, last_appid: {last_appid}, "
f"no more results, sleep {self.request_interval}s")
time.sleep(self.request_interval)
break

last_appid = response['last_appid']
print(f"IStoreService/GetAppList/v1: l: {language}, last_appid: {last_appid}, "
f"sleep {self.request_interval}s")
time.sleep(self.request_interval)
except Exception as ex:
print(f"IStoreService/GetAppList/v1: Error: {repr(ex)}, sleep {self.request_interval}s")
time.sleep(self.request_interval)
break
Empty file.
1 change: 1 addition & 0 deletions scripts/id_title_connector/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.32.3

0 comments on commit a6655bd

Please sign in to comment.