· 5 years ago · May 06, 2020, 11:02 AM
1import requests
2import json
3
4api = 'твой апи'
5
6response = requests.get('https://market.csgo.com/api/v2/my-inventory/?key=' + f'{api}')
7b = response.json()
8
9print(b)
10
11userData = json.load((open('C:\\pytest\\api.json')))
12
13userData.update(b)
14with open('C:\\pytest\\api.json', 'w') as file:
15 json.dump(userData, file, indent=4)
16 file.close()
17
18
19j = json.load((open('C:\\pytest\\api.json')))
20
21ping = requests.get('https://market.csgo.com/api/v2/ping?key=' + f'{api}')
22
23for x in j['items']:
24 try:
25 response4 = requests.get(
26 'https://market.csgo.com/api/BestSellOffer/' + x['classid'] + '_' + x['instanceid'] + '?key=' + f'{api}')
27 b4 = response4.json()
28 try:
29 item_name = x['market_hash_name']
30 item_price = b4['best_offer']
31 item_priceRUB = float(item_price) / 100
32 item = f'{item_name}' + ' : ' + f'{item_priceRUB}' + ' rub'
33 addToSale = requests.get('https://market.csgo.com/api/SetPrice/new_' + x['classid'] + '_' + x['instanceid'] + '/' + f'{item_price}' +'/?key=' + f'{api}')
34 print(item)
35 except KeyError:
36 pass
37 except json.decoder.JSONDecodeError:
38 pass