· 5 years ago · May 06, 2020, 01:44 PM
1import requests
2import json
3from time import sleep
4
5api = '9arvDmR41M9x1I4u1IBAw961nMiJa43'
6
7
8def Invet_check():
9 requests.get('https://market.csgo.com/api/v2/ping?key=' + f'{api}')
10 requests.get('https://market.csgo.com/api/v2/update-inventory/?key=' + f'{api}')
11 sleep(15)
12 response = requests.get('https://market.csgo.com/api/v2/my-inventory/?key=' + f'{api}')
13 b = response.json()
14 userData = json.load((open('C:\\pytest\\api.json')))
15 userData.update(b)
16 with open('C:\\pytest\\api.json', 'w') as file:
17 json.dump(userData, file, indent=4)
18 file.close()
19
20
21def itemsOnSale():
22 j = json.load((open('C:\\pytest\\api.json')))
23 for x in j['items']:
24 ping = requests.get('https://market.csgo.com/api/v2/ping?key=' + f'{api}')
25 try:
26 response4 = requests.get(
27 'https://market.csgo.com/api/BestSellOffer/' + x['classid'] + '_' + x[
28 'instanceid'] + '?key=' + f'{api}')
29 b4 = response4.json()
30 try:
31 item_name = x['market_hash_name']
32 item_price = b4['best_offer']
33 item_priceRUB = float(item_price) / 100
34 item = f'{item_name}' + ' по цене ' + f'{item_priceRUB}' + ' rub' + ' был успешно выставлен на продажу!'
35 if int(item_price) > 1000000:
36 pass
37 else:
38 requests.get('https://market.csgo.com/api/SetPrice/new_' + x['classid'] + '_' + x[
39 'instanceid'] + '/' + f'{item_price}' + '/?key=' + f'{api}')
40 print(item)
41 except KeyError:
42 pass
43 except json.decoder.JSONDecodeError:
44 pass
45 requests.get('https://market.csgo.com/api/v2/ping?key=' + f'{api}')
46 requests.get('https://market.csgo.com/api/v2/update-inventory/?key=' + f'{api}')
47 sleep(15)
48
49
50Invet_check()
51itemsOnSale()
52Invet_check()
53itemsOnSale()