-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDOAuctions.py
358 lines (285 loc) · 12.7 KB
/
DOAuctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import json, codecs
import time
import hashlib
import tkinter as tk
import re
import random
import datetime
import requests
from lxml import html
def isEmpty (clanAttrArr):
if (len(clanAttrArr) > 0):
return clanAttrArr[0]
return False
class MainApp:
def __init__ (self, master):
self.actions_list = [
"Manual resync",
"Show SID",
"Clear tracked"
]
self.tracked_auction_type = []
self.tracked_item_name = []
self.tracked_loot_id = []
self.tracked_credits = []
# Define elements
self.master = master
self.master.title("DOAuction Tool by MaksimGBV")
self.var_countdown_hour = tk.StringVar()
self.var_other = tk.StringVar()
self.var_price = tk.IntVar()
self.label_countdown = tk.Label(master, textvariable=self.var_countdown_hour)
self.entry_nickname = tk.Entry(master)
self.entry_password = tk.Entry(master)
self.entry_price = tk.Entry(master, textvariable=self.var_price)
self.entry_interval = tk.Entry(master)
self.button_login = tk.Button(master, text="Login", command=self.login)
self.button_sync = tk.OptionMenu(self.master, self.var_other, *self.actions_list)
self.button_bid = tk.Button(master, text="Bid once at the end", command=self.addTracked)
self.button_zombie = tk.Button(master, text="Zombie bidding", command=self.zombie)
self.scrlbar_auction = tk.Scrollbar(master)
self.listbox_items = tk.Listbox(master, selectmode=tk.SINGLE, width="90", height="13", yscrollcommand=self.scrlbar_auction.set)
self.listbox_status = tk.Listbox(master, height="3")
self.listbox_tracked = tk.Listbox(master, height="3")
# Set initial state
self.var_countdown_hour.set("Left: 00:00")
self.var_other.set("More")
self.var_other.trace("w", self.other_actions)
self.entry_nickname.insert(0, "Nickname")
self.entry_nickname.focus_set()
self.entry_password.insert(0, "Password")
self.var_price.set("Price in cr")
# self.entry_price.insert(0, "Price in cr")
self.entry_interval.insert(0, "Interval in s")
self.listbox_items.configure(font=("Consolas", 10))
self.scrlbar_auction.config(command=self.listbox_items.yview)
self.log("STATUS: Initialization... DONE")
# Put elements into the window
self.label_countdown.grid(row=0, column=2)
self.entry_nickname.grid(row=0, column=0)
self.entry_password.grid(row=0, column=1)
self.entry_price.grid(row=2, column=0)
self.entry_interval.grid(row=2, column=1)
self.button_login.grid(row=0, column=3, sticky=tk.W+tk.E)
self.button_sync.grid(row=0, column=4, columnspan=2, sticky=tk.W+tk.E)
self.button_bid.grid(row=2, column=2, columnspan=2, sticky=tk.W+tk.E)
self.button_zombie.grid(row=2, column=4, columnspan=2, sticky=tk.W+tk.E)
self.scrlbar_auction.grid(row=1, column=5, sticky=tk.N+tk.S)
self.listbox_items.grid(row=1, column=0, columnspan=5)
self.listbox_status.grid(row=3, column=0, columnspan=2, sticky=tk.W+tk.E)
self.listbox_tracked.grid(row=3, column=2, columnspan=4, sticky=tk.W+tk.E)
def login(self):
self.nickname = self.entry_nickname.get()
password = self.entry_password.get()
if self.auth():
self.log("STATUS: Checking license DONE")
self.session_requests = requests.session()
self.login_url = 'https://www.darkorbit.pl/'
result = self.session_requests.get(self.login_url)
self.log("STATUS: Collecting login info & tokens DONE")
tree = html.fromstring(result.text)
auth_token = list(set(tree.xpath("//input[@name='reloadToken']/@value")))[0]
login_destination = list(set(tree.xpath("//form[@name='bgcdw_login_form']/@action")))[0]
payload = {
'username': self.nickname,
'password': password,
'reloadToken': auth_token
}
result = self.session_requests.post(
login_destination,
payload,
headers = dict(referer=self.login_url)
)
self.log("STATUS: Logging in DONE")
if result.status_code == 200:
self.entry_nickname.config(state="disabled")
self.entry_password.delete(0, tk.END)
self.entry_password.insert(0, "*" * len(password))
self.entry_password.config(state="disabled")
self.button_login.config(state="disabled")
self.getAuctionState()
else:
self.log("ATTENTION: Checking license FAILED")
def sync(self):
self.master.after_cancel(self.timer)
self.getAuctionState()
def getAuctionState(self):
self.listbox_items.delete(0, tk.END)
self.auction_url = "https://pl2.darkorbit.com/indexInternal.es?action=internalAuction"
result = self.session_requests.get(
self.auction_url,
headers = dict(referer=self.login_url)
)
self.log("STATUS: Getting auction status DONE")
self.tic = time.perf_counter()
tree = html.fromstring(result.text)
cd = re.findall(r'\d+', re.findall(r'counterWeek.*myBidCount', result.text, re.DOTALL)[0])
countdown = {
"seconds" : int(cd[0]),
"minutes" : int(cd[1]),
"hours" : int(cd[2]),
"days" : int(cd[3])
}
self.hour_left = 0
self.hour_countdown_interval = random.randint(90, 180)
self.processCountdown(countdown)
self.sid = re.findall(r"'dosid=.*'", result.text)[0][7:-1]
self.auction_item = ['ITEM NAME'] + [x.strip() for x in tree.xpath("//td[@class='auction_item_name_col']/text()")]
self.auction_winner = ['WINNER'] + [x.strip() for x in tree.xpath("//td[@class='auction_item_highest']/text()")]
self.auction_current = ['CURRENT OFFER'] + [x.strip() for x in tree.xpath("//td[@class='auction_item_current']/text()")]
self.auction_you = ['YOUR OFFER'] + [x.strip() for x in tree.xpath("//td[@class='auction_item_you']/text()")]
self.item_loot_id = ['LOOT ID'] + [x.strip() for x in tree.xpath("//td[@class='auction_item_instant']/input[5]/@value")]
self.bid_destination = tree.xpath("//form[@name='placeBid']/@action")[0]
column_item = self.createColumn(self.auction_item)
column_winner = self.createColumn(self.auction_winner, True)
column_current = self.createColumn(self.auction_current, True)
column_you = self.createColumn(self.auction_you, True)
for i, item in enumerate(self.auction_item):
self.listbox_items.insert(
tk.END,
"{} {} {} {}".format(
column_item[i],
column_current[i],
column_you[i],
column_winner[i]
)
)
def addTracked(self):
if not self.listbox_items.curselection():
self.log("ATTENTION: Do not selected any item")
return 0
if self.listbox_items.curselection()[0] == 0:
self.log("ATTENTION: It's not an item")
return 0
if not isinstance(self.var_price.get(), int):
self.log("ATTENTION: Price is not an integer")
return 0
item_name = self.auction_item[self.listbox_items.curselection()[0]]
loot_id = self.item_loot_id[self.listbox_items.curselection()[0]]
credit = self.var_price.get()
if loot_id in self.tracked_loot_id:
if credit == self.tracked_credits[self.tracked_loot_id.index(loot_id)]:
self.log("ATTENTION: Item is already tracked")
return 0
else:
itemIndex = self.tracked_loot_id.index(loot_id)
self.tracked_auction_type.pop(itemIndex)
self.tracked_item_name.pop(itemIndex)
self.tracked_loot_id.pop(itemIndex)
self.tracked_credits.pop(itemIndex)
if len(self.tracked_auction_type) >= 3:
self.tracked_auction_type.pop(0)
self.tracked_item_name.pop(0)
self.tracked_loot_id.pop(0)
self.tracked_credits.pop(0)
self.tracked_auction_type.append("hour")
self.tracked_item_name.append(item_name)
self.tracked_loot_id.append(loot_id)
self.tracked_credits.append(credit)
self.updateTracked()
def updateTracked(self):
self.listbox_tracked.delete(0, tk.END)
if len(self.tracked_loot_id) < 1:
return 0
column_auction_type = self.createColumn(self.tracked_auction_type)
column_item_name = self.createColumn(self.tracked_item_name, True)
column_credits = self.tracked_credits
self.listbox_tracked.delete(0, tk.END)
for i, item in enumerate(self.tracked_auction_type):
self.listbox_tracked.insert(
tk.END,
"{} {} {}".format(
column_auction_type[i],
column_item_name[i],
column_credits[i]
)
)
def clearTracked(self):
self.tracked_auction_type = []
self.tracked_item_name = []
self.tracked_loot_id = []
self.tracked_credits = []
self.updateTracked()
def bid(self):
payload = {
"auctionType" : "hour",
"subAction" : "bid",
"lootId" : self.item_loot_id[self.listbox_items.curselection()[0]],
"credits" : int(self.var_price.get())
}
result = self.session_requests.post(
"https://pl2.darkorbit.com" + self.bid_destination,
payload,
headers = dict(referer=self.auction_url)
)
self.log("STATUS: Auto syncing")
self.getAuctionState()
def zombie(self):
pass
def processCountdown(self, countdown):
self.hour_left += 1
if self.hour_left == self.hour_countdown_interval:
self.log("STATUS: Auto syncing")
self.sync()
return
self.hour_remeaning = countdown['seconds'] + countdown['minutes'] * 60
if countdown['minutes'] == 0 and countdown['seconds'] < 10 and self.hour_left > 10:
self.log("STATUS: Auto syncing")
self.sync()
return
if countdown['minutes'] == 0 and countdown['seconds'] < 30 and self.hour_left > 30:
self.log("STATUS: Auto syncing")
self.sync()
return
if countdown['seconds'] > 0:
countdown['seconds'] -= 1
else:
countdown['seconds'] = 59
countdown['minutes'] -= 1
self.toc = time.perf_counter()
# print(str("{:7.4f}".format(self.toc - self.tic)))
self.updateCountdown(countdown)
self.timer = self.master.after(1000, self.processCountdown, countdown)
def updateCountdown(self, countdown):
self.var_countdown_hour.set("Left: {:02d}:{:02d}".format(countdown['minutes'], countdown['seconds']))
def other_actions(self, *args):
action = self.actions_list.index(self.var_other.get())
if action == 0:
self.var_other.set("More")
self.log("STATUS: Manual syncing")
self.sync()
elif action == 1:
self.var_other.set("More")
self.log("SID: " + self.sid)
elif action == 2:
self.var_other.set("More")
self.log("STATUS: Tracked items removed")
self.clearTracked()
else:
self.var_other.set("More")
def log(self, message):
datetime.datetime.now()
self.listbox_status.insert(0, str(datetime.datetime.now().strftime('%H:%M:%S')) + " " + message)
def auth(self):
auth_link = 'https://auth_server'
result = requests.get(
auth_link,
{ 'req' : hashlib.md5(b'salt_req' + self.nickname.encode()).hexdigest() }
)
if result.status_code == 200 and json.loads(result.text)['res'] == hashlib.md5(b'salt_res' + self.nickname.encode()).hexdigest():
return True
return False
def createColumn (self, arr, justifyRight = False):
longest = len(max(arr, key=len))
tmp = []
for element in arr:
whitespace = ' ' * (longest - len(element) + 1)
if justifyRight:
tmp.append(whitespace + element)
else:
tmp.append(element + whitespace)
return tmp
if __name__ == "__main__":
root = tk.Tk()
app = MainApp(root)
root.mainloop()