This repository has been archived by the owner on Jul 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gw2beta.py
276 lines (225 loc) · 9.04 KB
/
gw2beta.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
import mechanize
import cookielib
import sys
import re
from Tkinter import *
#self defined find function
def find(text, pattern, start):
"""Return the index of the first occurence of pattern in text starting
at start. Retun -1 if not found
find(str, str, int) -> int
"""
pattern_len = len(pattern)
text_len = len(text)
i = start
while i < text_len:
if pattern == text[i:i+pattern_len]:
return i
i += 1
return -1
#controls found by name
##control=br.form.find_control("controlname")
#searching:
def search():
"""Searches for an item in teh gw2spidy database fromk input, returns prices of item along with viability for flipping.
search()-> str"""
while True:
#Makes a browser object
br=mechanize.Browser()
#Sets cookies
cj =cookielib.LWPCookieJar()
br.set_cookiejar(cj)
#Sets the browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
#sets refresh rate for pages
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
#Debug messages on
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)
#Spoof a user agent
##br.addheader = [('User-agent', 'Mozilla/5.0 (X11; U; Linus i686; en-US; rv:1.9.0.1)Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
#Opening a site
r= br.open('http://gw2spidy.com')
html = r.read()
#print the source
##print html
#print the title
#print br.title()
#print response headers
#print r.info()
#show available forms for entering
## for f in br.forms():
## print "Form name:", f.name
## pass
#select the first form (has index of zero)
br.form=list(br.forms())[0]
#iterating through the controls in the form
#for control in br.form.controls:
# print control
# print "type=%s, name=%s valu=%s" % (control.type, control.name, br[control.name])
query=form.get()
br.form=list(br.forms())[0]
control.value=query
response= br.submit()
res=response.read()
w=open('scrape_current.txt', 'w')
w.write(res)
w.close()
findprice()
return False
def findprice():
f=open('scrape_current.txt', 'rU')
source=f.read()
source=str(source)
f.close()
##################################################################################
#sell
sell_index=source.find('Sell Price', 0)
sell_end_index=source.find('</td>', sell_index)
sellprice=source[sell_index:sell_end_index]
#Worth at least 1 gold
if find(sellprice, 'gold', 0) != -1:
gold_sell_index=sellprice.find('money-fragment',0)
gold_sell_end=sellprice.find('>g<',gold_sell_index)
gold_sell=sellprice[gold_sell_index:gold_sell_end]
gold_sell=gold_sell.replace("gw2money", '')
gold_sell=re.sub("\D", '', gold_sell)
silv_sell_index=sellprice.find('money-fragment',gold_sell_end)
silv_sell_end=sellprice.find('>s<',silv_sell_index)
silv_sell=sellprice[silv_sell_index:silv_sell_end]
silv_sell=silv_sell.replace("gw2money", '')
silv_sell=re.sub("\D", '', silv_sell)
if len(silv_sell)==0:
silv_sell='0'
cop_sell_index=sellprice.find('money-fragment',silv_sell_end)
cop_sell_end=sellprice.find('>c<',cop_sell_index)
cop_sell=sellprice[cop_sell_index:cop_sell_end]
cop_sell=cop_sell.replace("gw2money", '')
cop_sell=re.sub("\D", '', cop_sell)
if len(cop_sell)==0:
cop_sell='0'
#Worth at least 1 silver
elif find(sellprice, 'gold', 0) == -1 and find(sellprice, 'silver', 0) != -1:
silv_sell_index=sellprice.find('money-fragment',0)
silv_sell_end=sellprice.find('>s<',silv_sell_index)
silv_sell=sellprice[silv_sell_index:silv_sell_end]
silv_sell=silv_sell.replace("gw2money", '')
silv_sell=re.sub("\D", '', silv_sell)
cop_sell_index=sellprice.find('money-fragment',silv_sell_end)
cop_sell_end=sellprice.find('>c<',cop_sell_index)
cop_sell=sellprice[cop_sell_index:cop_sell_end]
cop_sell=cop_sell.replace("gw2money", '')
cop_sell=re.sub("\D", '', cop_sell)
if len(cop_sell) == 0:
cop_sell = '0'
gold_sell='0'
#Worth less than 1 silver
else:
cop_sell_index=sellprice.find('money-fragment',0)
cop_sell_end=sellprice.find('>c<',cop_sell_index)
cop_sell=sellprice[cop_sell_index:cop_sell_end]
cop_sell=cop_sell.replace("gw2money", '')
cop_sell=re.sub("\D", '', cop_sell)
silv_sell='0'
gold_sell='0'
#############################################################################################
#buy
buy_index=source.find('Buy Price', sell_end_index)
buy_end_index=source.find('</td>', buy_index)
buyprice=source[buy_index:buy_end_index]
#gold
if find(buyprice, 'gold', 0) != -1:
gold_buy_index=buyprice.find('money-fragment',0)
gold_buy_end=buyprice.find('>g<',gold_buy_index)
gold_buy=buyprice[gold_buy_index:gold_buy_end]
gold_buy=gold_buy.replace("gw2money", '')
gold_buy=re.sub("\D", '', gold_buy)
silv_buy_index=buyprice.find('money-fragment',gold_buy_end)
silv_buy_end=buyprice.find('>s<',silv_buy_index)
silv_buy=buyprice[silv_buy_index:silv_buy_end]
silv_buy=silv_buy.replace("gw2money", '')
silv_buy=re.sub("\D", '', silv_buy)
if len(silv_buy) == 0:
silv_buy ='0'
cop_buy_index=buyprice.find('money-fragment',silv_buy_end)
cop_buy_end=buyprice.find('>c<',cop_buy_index)
cop_buy=buyprice[cop_buy_index:cop_buy_end]
cop_buy=cop_buy.replace("gw2money", '')
cop_buy=re.sub("\D", '', cop_buy)
if len(cop_buy) == 0:
cop_buy='0'
#silver
elif find(buyprice, 'silver', 0) != -1:
silv_buy_index=buyprice.find('money-fragment',0)
silv_buy_end=buyprice.find('>s<',silv_buy_index)
silv_buy=buyprice[silv_buy_index:silv_buy_end]
silv_buy=silv_buy.replace("gw2money", '')
silv_buy=re.sub("\D", '', silv_buy)
cop_buy_index=buyprice.find('money-fragment',silv_buy_end)
cop_buy_end=buyprice.find('>c<',cop_buy_index)
cop_buy=buyprice[cop_buy_index:cop_buy_end]
cop_buy=cop_buy.replace("gw2money", '')
cop_buy=re.sub("\D", '', cop_buy)
if len(cop_buy) ==0:
cop_buy='0'
gold_buy='0'
#copper
else:
cop_buy_index=buyprice.find('money-fragment',0)
cop_buy_end=buyprice.find('>c<',cop_buy_index)
cop_buy=buyprice[cop_buy_index:cop_buy_end]
if len(cop_buy) != 0:
cop_buy=cop_buy.replace("gw2money", '')
cop_buy=re.sub("\D", '', cop_buy)
else:
cop_buy = '0'
silv_buy='0'
gold_buy='0'
print ("Buy: "+gold_buy + 'gold, '+ silv_buy+ 'silver, ' + cop_buy+'copper.')
print ("Sell: "+gold_sell + 'gold ' + silv_sell + 'silver ' + cop_sell+'copper.')
profit = (((int(gold_sell)*10000)+(int(silv_sell)*100)+int(cop_sell))*.85)-((int(gold_buy)*10000)+(int(silv_buy)*100)+int(cop_buy))
profit= round(profit)
profit = int(profit)
if profit > 0 :
profit=str(profit)
if len(profit) < 3:
prof=("Profit: " + profit + 'c')
result.config(text=prof)
pass
elif len(profit) == 3:
prof=("Profit: " + profit[0] + 's' + profit [1:] + 'c')
result.config(text=prof)
pass
elif len(profit) == 4:
prof=("Profit: " + profit[0]+ profit[1] + 's' + profit [2:] + 'c')
result.config(text=prof)
pass
elif len(profit) == 5:
prof=("Profit: " + profit[0] + 'g' + profit[1]+ profit[2] + 's' + profit[3:] + 'c')
result.config(text=prof)
pass
elif len(profit) == 6:
prof=("Profit: " + profit[0]+ profit[1] + 'g' + profit[2] + profit[3] + 's' + profit[4:] +'c')
result.config(text=prof)
pass
else:
prof= "Item flipping not viable."
result.config(text=prof)
return True
## return buyprice, sellprice
root = Tk()
root.title('Guild Wars 2 - Item Flipping')
label=Label(root, text='Enter item: ')
label.pack(side=LEFT)
form=Entry(root, width=20)
form.pack(side=LEFT)
calc=Button(root, bg="white", text="Check!", command=search)
calc.pack(side=LEFT)
result=Label(root, text='')
result.pack(side=LEFT)
root.mainloop()