F
F
frendri2019-04-02 19:10:31
Python
frendri, 2019-04-02 19:10:31

How to explain to the bot that one of my things is already in the first place?

So. I hope I can find an answer here. I've been scratching my head for the 4th day, because. this is my first program.
I am making an inquiry about my items that are currently on sale. The answer comes. Example:

{'success': True, 'items': [{'item_id': '555268962', 'assetid': '0', 'classid': '310779105', 'instanceid': '0', 'real_instance': '302028390', 'market_hash_name': 'Desert Eagle | Mudder (Minimal Wear)', 'position': 6, 'price': 9, 'currency': 'RUB', 'status': '1', 'live_time': 1231, 'left': None, 'botid': '0'}, {'item_id': '555268959', 'assetid': '0', 'classid': '310779105', 'instanceid': '0', 'real_instance': '302028390', 'market_hash_name': 'Desert Eagle | Mudder (Minimal Wear)', 'position': 5, 'price': 9, 'currency': 'RUB', 'status': '1', 'live_time': 1231, 'left': None, 'botid': '0'}, {'item_id': '555268953', 'assetid': '0', 'classid': '310779105', 'instanceid': '0', 'real_instance': '302028390', 'market_hash_name': 'Desert Eagle | Mudder (Minimal Wear)', 'position': 4, 'price': 9, 'currency': 'RUB', 'status': '1', 'live_time': 1231, 'left': None, 'botid': '0'}, {'item_id': '555268947', 'assetid': '0', 'classid': '310779105', 'instanceid': '0', 'real_instance': '302028390', 'market_hash_name': 'Desert Eagle | Mudder (Minimal Wear)', 'position': 3, 'price': 9, 'currency': 'RUB', 'status': '1', 'live_time': 1232, 'left': None, 'botid': '0'}, {'item_id': '555268935', 'assetid': '0', 'classid': '310779105', 'instanceid': '0', 'real_instance': '302028390', 'market_hash_name': 'Desert Eagle | Mudder (Minimal Wear)', 'position': 2, 'price': 9, 'currency': 'RUB', 'status': '1', 'live_time': 1232, 'left': None, 'botid': '0'}]}

Let's say I have 10 MP9 items | Bioleak (Field-Tested) for 10 rubles. But only one item is at position 1, all the rest are from 2 to 10.
I write: If the item is not at position 1, then the bot makes a request for the minimum price of this item among the entire market and lowers the price of my item by 1 kopeck below the minimum price, so that now my item is in position 1.
Dk here. He tested the First MP9 | Bioleak (Field-Tested). He is in position 1, the bot does nothing.
Then he checks the next MP9 | Bioleak (Field-Tested). It is in 2 positions, although the price is the same and there is no need to lower the price. But he downgrades, and so on with the next MP9 | Bioleak (Field-Tested).
Below is my code:
min_price = int(input())
i = 0
while True:
    try:
        item_req = 'https://market.csgo.com/api/v2/items?key=' + key
        json_string = requests.get(item_req)
        parsed_string = json.loads(json_string.text)
        if parsed_string['items'][i]['position'] != 1:
            search_item = 'https://market.csgo.com/api/v2/search-item-by-hash-name?key={0}&hash_name={1}'.format(key, name_item)
            json_str = requests.get(search_item)
            price_hash = json.loads(json_str.text)
            print(datetime.now().strftime("%H:%M:%S"), price_hash)
            price = price_hash['data'][i]['price']
            print(datetime.now().strftime("%H:%M:%S"), 'Минимальная цена предмета {0} RUB'.format(price/100))
            lowprice = price - 1
            print(datetime.now().strftime("%H:%M:%S"), 'Ставлю цену {0} на {1}'.format(lowprice/100, name_item))
            if lowprice >= min_price*100:
                item_id = (parsed_string['items'][i]['item_id'])
                set_price = 'https://market.csgo.com/api/v2/set-price?key={0}&item_id={1}&price={2}&cur=RUB'.format(key, item_id, lowprice)
                response = requests.get(set_price)
                setpr = json.loads(response.text)
                if setpr['success'] == True:
                    print(datetime.now().strftime("%H:%M:%S"), 'Успешно')
                time.sleep(10)
            else:
                print(datetime.now().strftime("%H:%M:%S"), 'Не могу понизить цену меньше минимальной')
        else:
            print(datetime.now().strftime("%H:%M:%S"), 'уже 1 позиция')
            time.sleep(10)
    i += 1
    except IndexError:
        pass

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question