forked from woctezuma/steam-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
steam_catalog_utils.py
70 lines (47 loc) · 1.93 KB
/
steam_catalog_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pathlib
import time
import steampi.json_utils
def download_steam_catalog():
url = 'https://api.steampowered.com/ISteamApps/GetAppList/v0002/'
(data, status_code) = steampi.json_utils.download_json_data(url)
success_flag = bool(data is not None)
downloaded_steam_catalog = {}
if success_flag:
# noinspection SpellCheckingInspection
for app in data['applist']['apps']:
# noinspection SpellCheckingInspection
app_id = str(app['appid'])
app_name = app['name']
downloaded_steam_catalog[app_id] = {}
downloaded_steam_catalog[app_id]['name'] = app_name
return downloaded_steam_catalog, success_flag, status_code
# noinspection SpellCheckingInspection
def get_json_filename_for_steam_catalog():
# Objective: return the filename of the Steam catalog
# Data folder
data_path = steampi.json_utils.get_data_path()
# Reference of the following line: https://stackoverflow.com/a/14364249
pathlib.Path(data_path).mkdir(parents=True, exist_ok=True)
# Get current day as yyyymmdd format
date_format = "%Y%m%d"
current_date = time.strftime(date_format)
json_base_filename = current_date + "_steam_catalog.json"
# Database filename
json_filename = data_path + json_base_filename
return json_filename
def load_steam_catalog():
json_filename = get_json_filename_for_steam_catalog()
try:
loaded_steam_catalog = steampi.json_utils.load_json_data(json_filename)
success_flag = True
status_code = None
except FileNotFoundError:
(loaded_steam_catalog, success_flag, status_code) = download_steam_catalog()
if success_flag:
steampi.json_utils.save_json_data(json_filename, loaded_steam_catalog)
return loaded_steam_catalog, success_flag, status_code
def main():
(_, _, _) = load_steam_catalog()
return True
if __name__ == '__main__':
main()