· 5 years ago · Feb 04, 2020, 10:10 AM
1import requests
2import json
3import datetime
4import time
5import threading
6from queue import Queue
7
8secret_key = '48R4q5Zzd7459FgPKGKYQje92RdjtH6'
9
10datas = list()
11datas_backup = list()
12
13countIter = 0
14
15
16def setPrice(secret_key, item_id, price):
17 try:
18 URL = 'https://market.csgo.com/api/v2/set-price?key=' + secret_key + '&item_id=' + str(
19 item_id) + '&price=' + str(price * 100) + '&cur=RUB'
20 resp = requests.get(URL).json()
21
22 except json.decoder.JSONDecodeError:
23 print(getOutPutTime(), 'JSON не найден! Проверьте корректность данных')
24
25
26def getOutPutTime():
27 return datetime.datetime.now().strftime('[%H:%M:%S] ')
28
29
30def Main():
31 URL = 'https://market.csgo.com/api/v2/update-inventory/?key=' + secret_key
32 resp = requests.get(URL)
33 Seller(secret_key)
34
35
36def Seller(secret_key):
37 try:
38 try:
39 try:
40 global datas
41 global countIter
42 global datas_backup
43 ixsa = 0
44 URL = 'https://market.csgo.com/api/v2/my-inventory/?key=48R4q5Zzd7459FgPKGKYQje92RdjtH6'
45 response = requests.get(URL)
46 for x in response.json()['items']:
47 # Тут кол-во предметов ставить)))
48 if ixsa < 10:
49 ITEM_URL = 'https://market.csgo.com/api/v2/search-item-by-hash-name?key=48R4q5Zzd7459FgPKGKYQje92RdjtH6&hash_name=' + \
50 x['market_hash_name']
51 item_response = requests.get(ITEM_URL)
52 price = 0.00;
53 for y in item_response.json()['data']:
54 price = float(y['price'] - 2) / 100
55 break
56 print(getOutPutTime(),
57 'Продаю предмет: ' + x['market_hash_name'] + ' за - ' + str(price) + 'RUB')
58 SellItemByID(x['id'], price, 'RUB')
59 data = x['market_hash_name'] + ":" + x['id']
60 datas.append(data)
61 datas_backup.append(data)
62 time.sleep(0.33)
63 ixsa += 1
64 countIter = ixsa
65 except json.decoder.JSONDecodeError:
66 print(getOutPutTime(), 'JSON не найден! Вещи на продажу не найдены или уже были распроданы!')
67 except ConnectionResetError:
68 print(getOutPutTime(), 'Соединение с сервером прервано! Проверьте подключение к интернету!')
69 except NameError:
70 print(getOutPutTime(), 'Вещи на продажу не найдены или уже были распроданы!')
71
72 CheckPrice(secret_key)
73
74
75def CheckPrice(secret_key):
76 try:
77 try:
78 try:
79 global countIter
80 countIterations = 0
81 newcountiter = countIter
82 while True:
83 item_name = ''
84 item_id = 0
85 id = 0
86 price = 0.00
87 global datas
88 global datas_backup
89 if countIterations == newcountiter:
90 print(getOutPutTime(), 'Запускаю новый цикл!')
91 datas = datas_backup.copy()
92 newcountiter += countIter
93 for c in datas:
94 c = c.split(':')
95 item_name = c[0]
96 item_id = c[1]
97 datas.pop(0)
98 break
99 if isSelled(secret_key, item_name) == True:
100 print(getOutPutTime(), 'Предмет был продан!')
101 continue
102 try:
103 URL = 'https://market.csgo.com/api/v2/search-item-by-hash-name-specific?key=' + secret_key + '&hash_name=' + item_name
104 resp = requests.get(URL).json()["data"]
105 except:
106 resp = {'response': False}
107 if resp['response'] == 'False' or resp['response'] == False:
108 continue
109 for i in resp:
110 price = i['price']
111 id = i['id']
112 break
113 price = float(price / 100)
114 if int(id) != int(item_id):
115 print(getOutPutTime(), 'Найден другой ТОП-1 предмет! Сбиваю цену!')
116 print(getOutPutTime(), 'Цена с ' + str(price) + ' сбита до ' + str(price - 0.02))
117 setPrice(secret_key, id, (price - 0.02))
118 else:
119 print(getOutPutTime(), 'Ваш предмет:' + item_name + ' всё еще ТОП-1')
120 countIterations += 1
121 # Тут задержку ставить
122 time.sleep(1)
123 except KeyError:
124 print(getOutPutTime(), 'Ошибка в поиске предмета! ну тут ряльна жопа')
125 CheckPrice(secret_key)
126 except NameError:
127 print(getOutPutTime(), 'Ошибка в парсинге JSON')
128 except json.decoder.JSONDecodeError:
129 print(getOutPutTime(), 'Ошибка JSON')
130 CheckPrice(secret_key)
131
132
133def isSelled(secret_key, name):
134 try:
135 URL = 'https://market.csgo.com/api/v2/items?key=' + secret_key
136 response = requests.get(URL).json['items']
137 for i in response:
138 item_status = i[i]['status']
139 item_hash_name = i[i]['market_hash_name']
140 if status == 2 and item_hash_name == name:
141 return True
142 else:
143 return False
144 except json.decoder.JSONDecodeError:
145 print(getOutPutTime(), 'Ошибка JSON')
146
147
148def SellItemByID(item_id, price, cur):
149 price = price * 100
150 URL = 'https://market.csgo.com/api/v2/add-to-sale?key=48R4q5Zzd7459FgPKGKYQje92RdjtH6&id=' + item_id + '&price=' + str(
151 price) + '&cur=' + cur
152 response = requests.get(URL).json()
153
154
155Main()