· 5 years ago · May 08, 2020, 10:38 AM
1import requests
2import json
3from time import sleep
4from threading import Thread
5from steampy.client import SteamClient
6
7api = '********************'
8api2 = '********************'
9i = 2
10# Set steam API key
11api_key = '*******************************'
12# Set path to SteamGuard file
13steamguard_path = 'C:/pytest/3/maFiles/*****************.maFile'
14# Steam username
15username = '*******************************'
16# Steam password
17password = '******************************'
18
19
20def trades(): # Проверка на наличие трейдов
21 client = SteamClient(api_key)
22 client.login(username, password, steamguard_path)
23 print('Вошли в аккаунт. Проверяем наличие трейдов..')
24 Checking_trades()
25
26
27def Checking_trades():
28 while i > 1:
29 sleep(5)
30 try:
31 sleep(5)
32 a = requests.get('https://market.csgo.com/api/v2/trade-request-give-p2p-all?key=' + f'{api}').json()
33 print(a)
34 if a['success'] == False:
35 sleep(30)
36 print('Офферов пока нету, ждем когда что-то появится...')
37 elif a['success'] == True:
38 b = requests.get('https://market.csgo.com/api/ItemRequest/in/1/?key=' + f'{api}').json()
39 print(b)
40 print('Создал запрос на передачу! Ждем пока sda подтвердит...')
41 sleep(15)
42 except json.decoder.JSONDecodeError:
43 print('Ошибка при проверке трейд офферов. Возможно лагают сервера тма или стима')
44 sleep(10)
45 Checking_trades()
46
47
48def updating():
49 try:
50 i = 2
51 while i > 1: # Обновление ивентаря и включение продаж каждые 3 минуты
52 inventUpdate()
53 ping()
54 sleep(160)
55 except json.decoder.JSONDecodeError:
56 print('Вылезла ошибка! Отдыхаю 15 секунд')
57 sleep(15)
58 Thread(target=updating).start()
59
60
61def ping():
62 status = requests.get('https://market.csgo.com/api/v2/ping?key=' + f'{api2}')
63 status2 = status.json()
64 print(status2)
65 if status2['success'] == True:
66 print('Продажи были успешно включены!')
67
68 elif status2['success'] == False and status2['message'] == 'too early for pong':
69 print('Продажи и так были включены')
70
71 else:
72 print('Ошибка включения продаж! Попробую еще раз через 160 секунд...')
73
74
75def inventUpdate():
76 status = requests.get('https://market.csgo.com/api/v2/update-inventory/?key=' + f'{api2}').json()
77 print(status)
78 if status['success'] == True:
79 print('Инвентарь был успешно обновлен!')
80 elif status['success'] == False:
81 print('Ошибка обновления инвентаря! Попробую еще раз через 160 секунд...')
82
83
84def Invet_check(): # Загрузка инвента
85 response = requests.get('https://market.csgo.com/api/v2/my-inventory/?key=' + f'{api}')
86 b = response.json()
87 userData = json.load((open('C:\\pytest\\api.json')))
88 userData.update(b)
89 with open('C:\\pytest\\api.json', 'w') as file:
90 json.dump(userData, file, indent=4)
91 file.close()
92
93
94def itemsOnSale():
95 j = json.load((open('C:\\pytest\\api.json')))
96 for x in j['items']:
97 try:
98 response4 = requests.get(
99 'https://market.csgo.com/api/BestSellOffer/' + x['classid'] + '_' + x[
100 'instanceid'] + '?key=' + f'{api}')
101 b4 = response4.json()
102 try:
103 item_name = x['market_hash_name']
104 item_price = b4['best_offer']
105 item_priceRUB = float(item_price) / 100
106 item = f'{item_name}' + ' по цене ' + f'{item_priceRUB}' + ' rub' + ' был успешно выставлен на продажу!'
107 if int(item_price) > 1000000:
108 pass
109 else:
110 requests.get('https://market.csgo.com/api/SetPrice/new_' + x['classid'] + '_' + x[
111 'instanceid'] + '/' + f'{item_price}' + '/?key=' + f'{api}')
112 print(item)
113 except KeyError:
114 pass
115 except json.decoder.JSONDecodeError:
116 pass
117
118
119def priceDump():
120 i = 2
121 while i > 1:
122 try:
123 list_items = requests.get('https://market.csgo.com/api/GetMySellOffers/?key=' + f'{api}').json()
124
125 userData = json.load((open('C:\\pytest\\position.json')))
126 userData.update(list_items)
127 with open('C:\\pytest\\position.json', 'w') as file:
128 json.dump(userData, file, indent=4)
129 file.close()
130
131 j = json.load((open('C:\\pytest\\position.json')))
132 for x in j['offers']:
133 try:
134 item_name = x['i_name']
135 position = x['position']
136 i_classid = x['i_classid']
137 ui_price = x['ui_price'] * 100
138 ui_id = x['ui_id']
139
140 if position == 1:
141 print('\n' +
142 'У предмета: ' + str(item_name) + '\n'
143 + 'Цена: ' + str(x['ui_price']) + ' рублей' + '\n'
144 + 'Предмет находится на 1 месте!' + '\n')
145
146 pass
147
148 elif position > 1:
149 print('\n' +
150 'У предмета: ' + str(item_name) + '\n'
151 + 'Цена: ' + str(x['ui_price']) + ' рублей' + '\n'
152 + 'Сейчас будем дампить цену! ' + '\n'
153 )
154 itemPOS_list = json.load((open('C:\\pytest\\itemPosition.json')))
155 classIn_list = itemPOS_list.get(i_classid)
156 if classIn_list == None:
157 while position > 1:
158 price = int(ui_price) - 1
159 ui_price = price
160
161 try:
162 position2 = int((requests.get(
163 'https://market.csgo.com/api/SetPrice/' + f'{ui_id}' + '/' + str(
164 price) + '/?key=' + f'{api}').json())['position'])
165 position = position2
166
167 print(
168 'Задампил цену! Теперь у предмета цена: ' + str(price) + ' и позиция: ' + str(
169 position))
170 itemPOS_list2 = json.load((open('C:\\pytest\\itemPosition.json')))
171 itemPOS_list2.update({str(i_classid): str(price)})
172 with open('C:\\pytest\\itemPosition.json', 'w') as file:
173 json.dump(itemPOS_list2, file, indent=4)
174 file.close()
175
176 except json.decoder.JSONDecodeError:
177 print('Произошла ошибка в дампе')
178 price = price + 1
179 pass
180
181
182 else:
183 try:
184 itemPOS_list2 = json.load((open('C:\\pytest\\itemPosition.json')))
185 price = itemPOS_list2.get(i_classid)
186 try:
187 position = int((requests.get(
188 'https://market.csgo.com/api/SetPrice/' + f'{ui_id}' + '/' + str(
189 price) + '/?key=' + f'{api}').json())['position'])
190 print(
191 '*/*/*/*/Задампил цену! Теперь у предмета цена: ' + str(
192 price) + ' и позиция: ' + str(
193 position))
194
195
196 except json.decoder.JSONDecodeError:
197 print('Произошла ошибка в дампе')
198 pass
199 except json.decoder.JSONDecodeError:
200 print('Произошла ошибка в дампе')
201 pass
202
203 except KeyError:
204 pass
205
206 data = {}
207 with open('C:\\pytest\\itemPosition.json', 'w') as file:
208 json.dump(data, file, indent=4)
209 file.close()
210
211
212
213 except json.decoder.JSONDecodeError:
214 priceDump()
215
216
217def sumItems():
218
219 items = (requests.get('https://market.csgo.com/api/Trades/?key=' + f'{api}').json())
220 totalPrice = 0
221 for item in items:
222 price = item['ui_price']
223 name = item['i_market_name']
224 totalPrice = int(totalPrice) + int(price)
225
226
227 print('На продаже: ' + str(totalPrice * 0.9) + ' рублей')
228 print('Баланс: ' + str(requests.get('https://market.csgo.com/api/GetMoney/?key=' + f'{api}').json()['money'] / 100))
229 full = str(float(totalPrice * 0.9) + float(requests.get('https://market.csgo.com/api/GetMoney/?key=' + f'{api}').json()['money'] / 100))
230 return full
231
232
233
234
235
236
237bot_action = input(
238 '"0" - включить продажи и обновление инвентаря' + '\n'
239 + '"1" - автоматичестки выставить все предметы по минимальной цене, включить передачу и продажи' + '\n'
240 + '"2" - выставить предметы на продажу по минимальной цене' + '\n'
241 + '"3" - включить автодамп цен + продажи (beta)'
242 + '"4" - узнать баланс предметов на продаже'
243 + 'Что нужно сделать?: ')
244
245if bot_action == '0':
246 Thread(target=updating).start()
247
248if bot_action == '1':
249 Thread(target=updating).start()
250 Thread(target=trades).start()
251 Invet_check()
252 itemsOnSale()
253
254if bot_action == '2':
255 Thread(target=updating).start()
256 Invet_check()
257 itemsOnSale()
258
259if bot_action == '3':
260 Thread(target=priceDump).start()
261 Thread(target=updating).start()
262 Thread(target=trades).start()
263
264if bot_action == '4':
265 print('В общем: ' + sumItems() + ' рублей')