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 71 72 73
|
"""
Steam app metadata
Copyright (c) 2010+, Anthony Garcia <anthony@lagg.me>
Distributed under the ISC License (see LICENSE)
"""
from . import api
class AppError(api.APIError):
pass
class app_list(object):
""" Retrieves a list of all Steam apps with their ID and localized name. """
_builtin = {
753: "Steam",
440: "Team Fortress 2",
520: "Team Fortress 2 Beta",
620: "Portal 2",
570: "DOTA 2",
205700: "DOTA 2 Test",
816: "DOTA 2 Internal",
730: "Counter Strike Global Offensive"
}
def __contains__(self, key):
try:
self[key]
return True
except KeyError:
return False
def __getitem__(self, key):
try:
return key, self._builtin[key]
except KeyError:
key = str(key).lower()
for app, name in self:
if str(app) == key or name.lower() == key:
return app, name
raise
def __init__(self, **kwargs):
self._api = api.interface("ISteamApps").GetAppList(version=2,
**kwargs)
self._cache = {}
def __iter__(self):
return next(self)
def __len__(self):
return len(self._apps)
@property
def _apps(self):
if not self._cache:
try:
self._cache = self._api["applist"]["apps"]
except KeyError:
raise AppError("Bad app list returned")
return self._cache
def __next__(self):
i = 0
data = self._apps
while(i < len(data)):
app = data[i]["appid"]
name = data[i]["name"]
i += 1
yield (app, name)
next = __next__
|