Пример #1
0
 def get_partner_inventory(self,
                           partner_steam_id: str,
                           game: GameOptions,
                           merge: bool = True) -> dict:
     params = {
         'sessionid': self._get_session_id(),
         'partner': partner_steam_id,
         'appid': int(game.app_id),
         'contextid': game.context_id
     }
     partner_account_id = steam_id_to_account_id(partner_steam_id)
     headers = {
         'X-Requested-With': 'XMLHttpRequest',
         'Referer': SteamUrl.COMMUNITY_URL + '/tradeoffer/new/?partner=' +
         partner_account_id,
         'X-Prototype-Version': '1.7'
     }
     response_dict = self._session.get(SteamUrl.COMMUNITY_URL +
                                       '/tradeoffer/new/partnerinventory/',
                                       params=params,
                                       headers=headers).json()
     if merge:
         return merge_items_with_descriptions_from_inventory(
             response_dict, game)
     return response_dict
Пример #2
0
    def get_my_inventory(self, game: GameOptions, merge: bool = True) -> dict:
        url = self.COMMUNITY_URL + '/my/inventory/json/' + \
              game.app_id + '/' + \
              game.context_id
        result = {}
        start = 0
        more = True
        while more:
            try:
                response_dict = self._session.get(url,
                                                  params={
                                                      'start': start
                                                  },
                                                  timeout=60).json()
                if not response_dict['success']:
                    logger.info("No items found for appid %s: %s", game.app_id,
                                response_dict)
                    return result
                more = response_dict['more']
                if merge:
                    result.update(
                        merge_items_with_descriptions_from_inventory(
                            response_dict, game))
                else:
                    result.update(response_dict['rgInventory'])
            except (json.decoder.JSONDecodeError, KeyError, TypeError) as err:
                logger.error('%s error while getting my inventory', err)
                time.sleep(5)
                continue

            start += 2000

        return result
Пример #3
0
    def _get_partner_inventory(self,
                               partner_steam_id: str,
                               game: GameOptions,
                               merge: bool = True,
                               count: int = 5000) -> dict:
        url = '/'.join([
            SteamUrl.COMMUNITY_URL, 'inventory', partner_steam_id, game.app_id,
            game.context_id
        ])
        params = {'l': 'english', 'count': count}
        response = self._session.get(url, params=params, stream=True)
        self._check_response(response)
        response.raise_for_status()
        response_dict = response.json()
        if not response_dict:
            raise NullInventory()
        if response_dict.get('error'):
            raise ApiException(response_dict['error'])
        if response_dict['success'] != 1:
            raise ApiException('Success value should be 1.')

        if merge:
            return merge_items_with_descriptions_from_inventory(
                response_dict, game)
        return response_dict
Пример #4
0
 def get_my_inventory(self, game: GameOptions, merge: bool = True) -> dict:
     url = SteamUrl.COMMUNITY_URL + '/my/inventory/json/' + \
           game.app_id + '/' + \
           game.context_id
     response_dict = self._session.get(url).json()
     if merge:
         return merge_items_with_descriptions_from_inventory(response_dict, game)
     return response_dict
Пример #5
0
 def get_partner_inventory(self, partner_steam_id: str, game: GameOptions, merge: bool = True, count: int = 5000) -> dict:
     url = '/'.join([SteamUrl.COMMUNITY_URL, 'inventory', partner_steam_id, game.app_id, game.context_id])
     params = {'l': 'english',
               'count': count}
     response_dict = self._session.get(url, params=params).json()
     if response_dict['success'] != 1:
         raise ApiException('Success value should be 1.')
     if merge:
         return merge_items_with_descriptions_from_inventory(response_dict, game)
     return response_dict