steampy icon indicating copy to clipboard operation
steampy copied to clipboard

Add params in get_partner_inventory

Open SiSiska opened this issue 1 year ago • 7 comments

OLD:

   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 is None or response_dict.get('success') != 1:
            raise ApiException('Success value should be 1.')

        return merge_items_with_descriptions_from_inventory(response_dict, game) if merge else response_dict

NEW:

    def get_partner_inventory(
        self, partner_steam_id: str, game: GameOptions, merge: bool = True, count: int = 5000, last_assetid: int = None
    ) -> dict:
        url = '/'.join((SteamUrl.COMMUNITY_URL, 'inventory', partner_steam_id, game.app_id, game.context_id, ))
        params = {'l': 'english', 'count': count, "start_assetid": f"start_assetid={last_assetid}" if last_assetid else ""}

        response_dict = self._session.get(url, params=params).json()
        if response_dict is None or response_dict.get('success') != 1:
            raise ApiException('Success value should be 1.')

        return merge_items_with_descriptions_from_inventory(response_dict, game) if merge else response_dict

SiSiska avatar Feb 03 '24 12:02 SiSiska

What is this? And for which file?

lspeed-v avatar Feb 03 '24 14:02 lspeed-v

Простите. Мой программист язык очень плохой. =) Спустя несколько часов тестов я понял что я пока что еще глуп что бы делать такие предложения, но проблема все же имеется оригинале. В общем и целом запрашивая инвентарь пользователя объемом более 5000 предметов мы получим только первые 5000. Что бы получить 5001 предмет, нам нужно знать last_assetid. Как его получить в steampy я не понял. Но знаю что дело в utils.py. Мы получаем только assets: value, а нужно получить ВЕСЬ json ответ, что бы в будущем использовать дополнительные парамеры.

translete G:

Sorry. My programmer language is very bad. =) After several hours of testing, I realized that I am still stupid to make such proposals, but the problem still exists in the original. In general, when requesting a user's inventory of more than 5000 items, we will only get the first 5000. To get 5001 items, we need to know the last_assetid. I don't understand how to get it in steampy. But I know that the problem is in utils.py. We only get assets: value, but we need to get the ALL json response in order to use additional parameters in the future.

SiSiska avatar Feb 03 '24 16:02 SiSiska

Did you try to raise “count” argument which is 5000 now?

lspeed-v avatar Feb 03 '24 16:02 lspeed-v

Did you try to raise “count” argument which is 5000 now?

No, the maximum value is count=5000. This is a steam request limit. I wanted to get an inventory that has more than 5000 items, for example 6000. To get 5001-6000 items, you need to know last_assetid and pass &start_assetid=last_assetid in the request

SiSiska avatar Feb 03 '24 17:02 SiSiska

Could you give me an example account with 5000+ items on it, i'll try to solve it

lspeed-v avatar Feb 03 '24 17:02 lspeed-v

https://steamcommunity.com/id/officialstmbot

SiSiska avatar Feb 03 '24 17:02 SiSiska

Я написал свой парсер инвентаря. в котором проверяется "more_items". Также сделал примитивную защиту от ошибки 429.

Но топик не закрываю, так как считаю это недоработкой. Еще steampy требует обязательной авторизации для парсинга инвентаря, что не нужно.

I wrote my own inventory parser. in which 'more_items' is checked. I also made a primitive protection against error 429.

But I’m not closing the topic, because I don’t think it’s an improvement. Steampy also requires mandatory authorization to parse inventory, which is not necessary.

SiSiska avatar Feb 03 '24 21:02 SiSiska