33 lines
879 B
Python
33 lines
879 B
Python
import requests
|
|
|
|
|
|
class SteamApps:
|
|
__instance = None
|
|
|
|
@staticmethod
|
|
def get_instance():
|
|
""" Static access method. """
|
|
if not SteamApps.__instance:
|
|
SteamApps()
|
|
return SteamApps.__instance
|
|
|
|
def __init__(self):
|
|
""" Virtually private constructor. """
|
|
if SteamApps.__instance:
|
|
raise Exception("This class is a singleton!")
|
|
else:
|
|
SteamApps.__instance = self
|
|
|
|
# Load steam appid <-> game list
|
|
r = requests.get("http://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json")
|
|
|
|
if r.status_code == 200:
|
|
self.glist = r.json()
|
|
else:
|
|
self.glist = None
|
|
|
|
def appid2game(self, appid):
|
|
for game in self.glist["applist"]["apps"]:
|
|
if appid == game["appid"]:
|
|
return game
|