How to use the steam.items.InventoryError function in steam

To help you get started, we’ve selected a few steam examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Lagg / optf2 / optf2 / app / sim.py View on Github external
def GET(self, user):
        baseurl = user.strip('/').split('/')
        if len(baseurl) > 0:
            user = baseurl[-1]

        if not user: raise steam.items.InventoryError("Need an ID")

        try:
            prof = database.user(user).load()
            ctx = database.sim_context(prof).load()

            return templates.sim_selector(prof, ctx)
        except steam.items.InventoryError as E:
            raise web.NotFound(error_page.generic("Failed to load backpack ({0})".format(E)))
        except steam.user.ProfileError as E:
            raise web.NotFound(error_page.generic("Failed to load profile ({0})".format(E)))
        except steam.api.HTTPError as E:
            raise web.NotFound(error_page.generic("Couldn't connect to Steam (HTTP {0})".format(E)))
        except database.CacheEmptyError as E:
            raise web.NotFound(error_page.generic(E))
github Lagg / optf2 / optf2 / inventory_views.py View on Github external
def GET(self, user):
        baseurl = user.strip('/').split('/')
        if len(baseurl) > 0:
            user = baseurl[-1]

        if not user:
            raise steam.items.InventoryError("Need an ID")

        try:
            prof = models.user(user).load()
            ctx = models.sim_context(prof).load()
            for ct in (ctx or []):
                ct.setdefault("inventory_logo", '')

            return template.sim_selector(prof, ctx)
        except steam.items.InventoryError as E:
            raise web.NotFound(template.errors.generic("Failed to load backpack ({0})".format(E)))
        except steam.user.ProfileError as E:
            raise web.NotFound(template.errors.generic("Failed to load profile ({0})".format(E)))
        except steam.api.HTTPError as E:
            raise web.NotFound(template.errors.generic("Couldn't connect to Steam (HTTP {0})".format(E)))
        except models.CacheEmptyError as E:
            raise web.NotFound(template.errors.generic(E))
github Lagg / steamodd / steam / sim.py View on Github external
def __init__(self, app, profile, schema=None, section=None, timeout=None, lang=None):
        """
        app is context data as returned by 'inventory_context.get'
        profile is a valid user object or ID64
        """

        self._cache = {}
        self._section = section
        self._ctx = app
        self._timeout = timeout or api.socket_timeout.get()
        self._language = loc.language(lang).name.lower()

        if not app:
            raise items.InventoryError("No inventory available")

        try:
            sid = profile.id64
        except AttributeError:
            sid = profile

        self._user = sid
github FAForever / server / steam / sim.py View on Github external
def __init__(self, app, profile, schema = None, section = None, timeout = None):
        """
        app is context data as returned by 'inventory_context.get'
        profile is a valid user object or ID64
        """

        self._cache = {}
        self._section = section
        self._ctx = app
        self._timeout = timeout or api.socket_timeout.get()

        if not app:
            raise items.InventoryError("No inventory available")

        try:
            sid = profile.id64
        except AttributeError:
            sid = profile

        self._user = sid
github Lagg / steamodd / steam / sim.py View on Github external
for sec in downloadlist:
            page_url = url + sec

            if self._language:
                page_url += "?l=" + self._language

            req = api.http_downloader(page_url, timeout=self._timeout)
            inventorysection = json.loads(req.download().decode("utf-8"))

            if not inventorysection:
                raise items.InventoryError("Empty context data returned")

            try:
                itemdescs = inventorysection["rgDescriptions"]
            except KeyError:
                raise items.InventoryError("Steam returned inventory with missing context")

            inv = inventorysection.get("rgInventory")
            if not inv:
                continue

            for id, item in inv.items():
                # Store the section ID for later use
                item["sec"] = sec
                item.update(itemdescs.get(item["classid"] + "_" + item["instanceid"], {}))
                merged_items.append(item)

        self._cache = {"cells": cellcount, "items": merged_items}
        return self._cache
github Lagg / steamodd / steam / sim.py View on Github external
def ctx(self):
        if self._cache:
            return self._cache

        try:
            data = self._downloader.download()
            contexts = re.search("var g_rgAppContextData = (.+);",
                                 data.decode("utf-8"))
            match = contexts.group(1)
            self._cache = json.loads(match)
        except:
            raise items.InventoryError("No SIM inventory information available for this user")

        return self._cache
github FAForever / server / steam / items.py View on Github external
if self._cache:
            return self._cache

        status = None

        try:
            status = self._api["result"]["status"]
            items = self._api["result"]["items"]
        except KeyError:
            # Only try to check status code if items don't exist (why error out when items are there)
            if status is not None:
                if status == 8:
                    raise BadID64Error("Bad Steam ID64 given")
                elif status == 15:
                    raise ProfilePrivateError("Profile is private")
            raise InventoryError("Backpack data incomplete or corrupt")

        self._cache = {
                "items": items,
                "cells": self._api["result"].get("num_backpack_slots", len(items))
                }

        return self._cache
github Lagg / steamodd / steam / items.py View on Github external
pass


class AssetError(api.APIError):
    pass


class InventoryError(api.APIError):
    pass


class BadID64Error(InventoryError):
    pass


class ProfilePrivateError(InventoryError):
    pass


class schema(object):
    """ Wrapper for item schema of certain games from Valve. Those are currently
    available (along with their ids):

        * ``260`` - Counter Strike: Source Beta
        * ``440`` - Team Fortress 2
        * ``520`` - Team Fortress 2 Public Beta
        * ``570`` - Dota 2
        * ``620`` - Portal 2
        * ``710`` - Counter-Strike: Global Offensive Beta Dev
        * ``816`` - Dota 2 internal test
        * ``841`` - Portal 2 Beta
        * ``205790`` - Dota 2 (beta) test
github Lagg / steamodd / steam / items.py View on Github external
return self._cache

        status = None

        try:
            status = self._api["result"]["status"]
            items = self._api["result"]["items"]
        except KeyError:
            # Only try to check status code if items don't exist (why error out
            # when items are there)
            if status is not None:
                if status == 8:
                    raise BadID64Error("Bad Steam ID64 given")
                elif status == 15:
                    raise ProfilePrivateError("Profile is private")
            raise InventoryError("Backpack data incomplete or corrupt")

        self._cache = {
                "items": items,
                "cells": self._api["result"].get("num_backpack_slots", len(items))
                }

        return self._cache