def load(self, sid): """ Loads or refreshes the player backpack for the given steam.user Returns a list of items, will be empty if there's nothing in the backpack""" if not isinstance(sid, base.user.profile): sid = base.user.profile(sid) id64 = sid.get_id64() url = ("http://api.steampowered.com/IEconItems_" + self._app_id + "/GetPlayerItems/" "v0001/?key=" + base.get_api_key() + "&format=json&SteamID=") inv = urllib2.urlopen(url + str(id64)).read() # Once again I'm doing what Valve should be doing before they generate # JSON. WORKAROUND self._inventory_object = json.loads(inv.replace("-1.#QNAN0", "0")) result = self._inventory_object["result"]["status"] if result == 8: raise Error("Bad SteamID64 given") elif result == 15: raise Error("Profile set to private") elif result != 1: raise Error("Unknown error") itemlist = self._inventory_object["result"]["items"] if len(itemlist) and itemlist[0] == None: self._inventory_object["result"]["items"] = []
def __init__(self, appid, sid, oschema = None): """ Loads the backpack of user sid if given, generates a fresh schema object if one is not given. """ self._schema = oschema self._app_id = str(appid) self._profile = sid if not isinstance(self._profile, base.user.profile): self._profile = base.user.profile(self._profile) url = ("http://api.steampowered.com/IEconItems_{0}/GetPlayerItems/v0001/?key={1}&format=json&SteamID={2}").format( self._app_id, base.get_api_key(), self._profile.get_id64()) super(backpack, self).__init__(url) if not self._schema: self._schema = schema() # Once again I'm doing what Valve should be doing before they generate # JSON. WORKAROUND self._inventory_object = self._deserialize(self._download().replace("-1.#QNAN0", "0")) result = self._inventory_object["result"]["status"] if result == 8: raise Error("Bad SteamID64 given") elif result == 15: raise Error("Profile set to private") elif result != 1: raise Error("Unknown error") itemlist = self._inventory_object["result"]["items"] if len(itemlist) and itemlist[0] == None: self._inventory_object["result"]["items"] = []
def __init__(self, appid, lang = None, currency = None, lm = None): """ lang: Language of asset tags, defaults to english currency: The iso 4217 currency code, returns all currencies by default """ self._language = lang or "en" self._currency = currency self._app_id = appid url = ("http://api.steampowered.com/ISteamEconomy/GetAssetPrices/v0001?" + "key={0}&format=json&language={1}&appid={2}".format(base.get_api_key(), self._language, self._app_id)) if self._currency: url += "¤cy=" + self._currency super(assets, self).__init__(url, lm) downloadfunc = None if lm: downloadfunc = self._download_cached else: downloadfunc = self._download res = self._deserialize(downloadfunc()) try: adict = self._deserialize(self._download())["result"] if not adict.get("success", False): raise AssetError("Server failed to return catalog") self._tag_map = adict["tags"] self._assets = {} for asset in adict["assets"]: self._assets[asset["name"]] = asset_item(asset, self) except KeyError as E: raise AssetError("Bad asset list")
def load(self, sid): """ Loads or refreshes the player backpack for the given steam.user Returns a list of items, will be empty if there's nothing in the backpack""" if not isinstance(sid, base.user.profile): sid = base.user.profile(sid) id64 = sid.get_id64() url = ( "http://api.steampowered.com/IEconItems_" + self._app_id + "/GetPlayerItems/" "v0001/?key=" + base.get_api_key() + "&format=json&SteamID=" ) inv = urllib2.urlopen(url + str(id64)).read() # Once again I'm doing what Valve should be doing before they generate # JSON. WORKAROUND self._inventory_object = json.loads(inv.replace("-1.#QNAN0", "0")) result = self._inventory_object["result"]["status"] if result == 8: raise Error("Bad SteamID64 given") elif result == 15: raise Error("Profile set to private") elif result != 1: raise Error("Unknown error") itemlist = self._inventory_object["result"]["items"] if len(itemlist) and itemlist[0] == None: self._inventory_object["result"]["items"] = []
def __init__(self, lang=None, currency=None): """ lang: Language of asset tags, defaults to english currency: The iso 4217 currency code, returns all currencies by default """ if not lang: lang = "en" self._language = lang self._currency = currency self._url = ( "http://api.steampowered.com/ISteamEconomy/GetAssetPrices/v0001?" + "key={0}&format=json&language={1}&appid={2}".format(base.get_api_key(), self._language, self._app_id) ) if self._currency: self._url += "¤cy=" + self._currency try: adict = self._deserialize(self._download())["result"] if not adict.get("success", False): raise AssetError("Server failed to return catalog") self._tag_map = adict["tags"] self._assets = {} for asset in adict["assets"]: for prop in asset["class"]: if prop.get("name") == "def_index": self._assets[int(prop.get("value"))] = asset break except KeyError as E: raise AssetError("Bad asset list")
def __init__(self, lang=None, currency=None): """ lang: Language of asset tags, defaults to english currency: The iso 4217 currency code, returns all currencies by default """ if not lang: lang = "en" self._language = lang self._currency = currency self._url = ( "http://api.steampowered.com/ISteamEconomy/GetAssetPrices/v0001?" + "key={0}&format=json&language={1}&appid={2}".format( base.get_api_key(), self._language, self._app_id)) if self._currency: self._url += "¤cy=" + self._currency try: adict = self._deserialize(self._download())["result"] if not adict.get("success", False): raise AssetError("Server failed to return catalog") self._tag_map = adict["tags"] self._assets = {} for asset in adict["assets"]: for prop in asset["class"]: if prop.get("name") == "def_index": self._assets[int(prop.get("value"))] = asset break except KeyError as E: raise AssetError("Bad asset list")
def __init__(self, vanity, **kwargs): """ Takes a vanity URL part and tries to resolve it. """ url = ("http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?" + urllib.urlencode({"key": base.get_api_key(), "vanityurl": vanity})) super(vanity_url, self).__init__(url, **kwargs)
def __init__(self, appid, lang = None, lm = None): """ schema will be used to initialize the schema if given, lang can be any ISO language code. lm will be used to generate an HTTP If-Modified-Since header. """ self._language = lang or "en" self._class_map = MapDict() self._app_id = str(appid) super(schema, self).__init__("http://api.steampowered.com/IEconItems_" + self._app_id + "/GetSchema/v0001/?key=" + base.get_api_key() + "&format=json&language=" + self._language, last_modified = lm) downloadfunc = None if lm: downloadfunc = self._download_cached else: downloadfunc = self._download res = self._deserialize(downloadfunc()) if not res or res["result"]["status"] != 1: raise SchemaError("Schema error", res["result"]["status"]) self._attributes = {} self._attribute_names = {} for attrib in res["result"]["attributes"]: # WORKAROUND: Valve apparently does case insensitive lookups on these, so we must match it self._attributes[attrib["defindex"]] = attrib self._attribute_names[attrib["name"].lower()] = attrib["defindex"] self._items = {} for item in res["result"]["items"]: self._items[item["defindex"]] = item self._qualities = {} for k,v in res["result"]["qualities"].iteritems(): aquality = {"id": v, "str": k, "prettystr": k} try: aquality["prettystr"] = res["result"]["qualityNames"][aquality["str"]] except KeyError: pass self._qualities[v] = aquality self._particles = {} for particle in res["result"].get("attribute_controlled_attached_particles", []): self._particles[particle["id"]] = particle self._item_ranks = {} for rankset in res["result"].get("item_levels", []): self._item_ranks[rankset["name"]] = rankset["levels"] self._kill_types = {} for killtype in res["result"].get("kill_eater_score_types", []): self._kill_types[killtype["type"]] = killtype self._origins = {} for origin in res["result"].get("originNames", []): self._origins[origin["origin"]] = origin
def __init__(self, sid = None): """ Creates a profile instance for the given user """ self._profile_url = ("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/" "v0002/?key=" + base.get_api_key() + "&steamids=") if isinstance(sid, dict): self._summary_object = sid elif sid: self.get_summary(sid)
def __init__(self, lang=None): """ schema will be used to initialize the schema if given, lang can be any ISO language code. """ schema = None if not lang: lang = "en" self._language = lang self._url = ( "http://api.steampowered.com/IEconItems_" + self._app_id + "/GetSchema/v0001/?key=" + base.get_api_key() + "&format=json&language=" + lang ) schema = self._deserialize(self._download()) if not schema or schema["result"]["status"] != 1: raise SchemaError("Schema error", schema["result"]["status"]) self._attributes = {} self._attribute_names = {} for attrib in schema["result"]["attributes"]: # WORKAROUND: Valve apparently does case insensitive lookups on these, so we must match it self._attributes[attrib["defindex"]] = attrib self._attribute_names[attrib["name"].lower()] = attrib["defindex"] self._items = {} for item in schema["result"]["items"]: self._items[item["defindex"]] = item self._qualities = {} for k, v in schema["result"]["qualities"].iteritems(): aquality = {"id": v, "str": k, "prettystr": k} try: aquality["prettystr"] = schema["result"]["qualityNames"][aquality["str"]] except KeyError: pass self._qualities[v] = aquality self._particles = {} for particle in schema["result"].get("attribute_controlled_attached_particles", []): self._particles[particle["id"]] = particle self._item_ranks = {} for rankset in schema["result"].get("item_levels", []): self._item_ranks[rankset["name"]] = rankset["levels"] self._kill_types = {} for killtype in schema["result"].get("kill_eater_score_types", []): self._kill_types[killtype["type"]] = killtype["type_name"]
def __init__(self, lang=None): """ schema will be used to initialize the schema if given, lang can be any ISO language code. """ schema = None if not lang: lang = "en" self._language = lang self._url = ("http://api.steampowered.com/IEconItems_" + self._app_id + "/GetSchema/v0001/?key=" + base.get_api_key() + "&format=json&language=" + lang) schema = self._deserialize(self._download()) if not schema or schema["result"]["status"] != 1: raise SchemaError("Schema error", schema["result"]["status"]) self._attributes = {} self._attribute_names = {} for attrib in schema["result"]["attributes"]: # WORKAROUND: Valve apparently does case insensitive lookups on these, so we must match it self._attributes[attrib["defindex"]] = attrib self._attribute_names[attrib["name"].lower()] = attrib["defindex"] self._items = {} for item in schema["result"]["items"]: self._items[item["defindex"]] = item self._qualities = {} for k, v in schema["result"]["qualities"].iteritems(): aquality = {"id": v, "str": k, "prettystr": k} try: aquality["prettystr"] = schema["result"]["qualityNames"][ aquality["str"]] except KeyError: pass self._qualities[v] = aquality self._particles = {} for particle in schema["result"].get( "attribute_controlled_attached_particles", []): self._particles[particle["id"]] = particle self._item_ranks = {} for rankset in schema["result"].get("item_levels", []): self._item_ranks[rankset["name"]] = rankset["levels"] self._kill_types = {} for killtype in schema["result"].get("kill_eater_score_types", []): self._kill_types[killtype["type"]] = killtype["type_name"]
def __init__(self, sid, **kwargs): """ Creates a profile instance for the given user """ url = ("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/" "v2/?key=" + base.get_api_key() + "&steamids=") sid = str(sid) lsid = sid.rfind('/') if (lsid + 1) >= len(sid): sid = sid[:lsid] sid = os.path.basename(sid) super(profile, self).__init__(url + sid, **kwargs) self._sid = sid self._base_url = url
def __init__(self): """ Fetch the ever-useful and ever-changing wrench owner list """ url = ("http://api.steampowered.com/ITFItems_{0}/GetGoldenWrenches/" + "v2/?key={1}&format=json").format(_APP_ID, base.get_api_key()) super(golden_wrench, self).__init__(url) try: self._idmap = {} for wrench in self._deserialize(self._download())["results"]["wrenches"]: rw = golden_wrench_item(wrench) self._idmap[rw.get_craft_number()] = rw self._idmap[rw.get_id()] = rw except Exception as E: raise GoldenWrenchError("Failed to fetch wrench list: " + str(E))
def __init__(self): """ Fetch the ever-useful and ever-changing wrench owner list """ url = ("http://api.steampowered.com/ITFItems_{0}/GetGoldenWrenches/" + "v2/?key={1}&format=json").format(_APP_ID, base.get_api_key()) super(golden_wrench, self).__init__(url) try: self._idmap = {} for wrench in self._deserialize( self._download())["results"]["wrenches"]: rw = golden_wrench_item(wrench) self._idmap[rw.get_craft_number()] = rw self._idmap[rw.get_id()] = rw except Exception as E: raise GoldenWrenchError("Failed to fetch wrench list: " + str(E))
def __init__(self, vanity): """ Takes a vanity URL part and tries to resolve it. """ self._url = ("http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?" + urllib.urlencode({"key": base.get_api_key(), "vanityurl": vanity})) try: result = json.load(urllib2.urlopen(self._url))["response"] scode = int(result["success"]) except Exception as E: raise VanityError(E) if scode != 1: raise VanityError(result["message"], scode) self._id64 = long(result["steamid"]) self._vanity = vanity
def __init__(self, appid, ugcid64, user = None, **kwargs): uid = None if user: try: uid = user.get_id64() except AttributeError: uid = user url = ("http://api.steampowered.com/ISteamRemoteStorage/" + "GetUGCFileDetails/v1?ugcid={0}&appid={1}&key={2}").format(ugcid64, appid, base.get_api_key()) if uid: url += "&steamid=" + str(uid) super(user_ugc, self).__init__(url, **kwargs)
def _get_download_url(self): return ("http://api.steampowered.com/ITFItems_440/GetGoldenWrenches/" "v2/?key=" + base.get_api_key() + "&format=json")
def __init__(self): """ Fetch the ever-useful and ever-changing wrench owner list """ url = ("http://api.steampowered.com/ITFItems_{0}/GetGoldenWrenches/" + "v2/?key={1}&format=json").format(_APP_ID, base.get_api_key()) super(golden_wrench, self).__init__(url)