-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzeidianji_ranch.py
308 lines (258 loc) · 7.98 KB
/
zeidianji_ranch.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
# coding=gbk
####configuration begin####
import ConfigParser
import sys, os
pathname = os.path.dirname(sys.argv[0])
full_path= os.path.abspath(pathname)
full_path_name=os.path.join(full_path,'config.ini')
config = ConfigParser.RawConfigParser()
config.read(full_path_name)
if(not config.has_section('ACCOUNT')):
account_name=raw_input("开心网用户名:")
account_password=raw_input("开心网密码:")
config.add_section('ACCOUNT')
config.set('ACCOUNT', 'account_name', account_name)
config.set('ACCOUNT', 'account_password', account_password)
with open(full_path_name, 'wb') as configfile:
config.write(configfile)
else:
account_name = config.get('ACCOUNT', 'account_name')
account_password = config.get('ACCOUNT', 'account_password')
if(config.has_section('GARDEN')):
seedid_blacklist = config.get('GARDEN', 'seedid_blacklist')
seedid_blacklist = seedid_blacklist.split(',')
else:
seedid_blacklist=[]
####configuration end####
def printD(document,path):
f=open(path,'w')
f.write(document)
f.close()
import urllib2
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor())
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib2.install_opener(opener)
host='http://www.kaixin001.com/'
#01 login
data='url=/home/&email=%s&password=%s' % (account_name,account_password)
req = urllib2.Request(url='http://www.kaixin001.com/login/login.php', \
data=data)
f = urllib2.urlopen(req)
print "login..."
assert 200==f.code
req = urllib2.Request(url='http://www.kaixin001.com/!house/index.php')
f = urllib2.urlopen(req)
print "GET /!house/index.php"
print f.msg
assert 200==f.code
#03.1 get parameter
for line in f:
if(line.find(r'FlashVars')>=0):
break
#没找到参数,说明登陆失败
if(line.find(r'FlashVars')<0):
print "登陆失败,请检查config.ini中的用户名和密码"
sys.exit(-1)
#解析参数
l=line.split(',')
l1=l[1]
param=l1[2:-1] #remove ' at two ends
print param
#param='verify=82793720_1062_82793720_1241615280_1f83fcd2117fd3aca6bbe7da595cf4c0&wwwhost=www.kaixin001.com&roomid=8710&roomsnum=2&fuid=0'
#取得主人id
hostid=param[param.find('='):param.find('_')]
#03.2 split parameter
plist=param.split('&')
pdict={}
for p in plist:
pair=p.split('=')
pdict[pair[0]]=pair[1]
#getconf function
#GET /!house/!ranch//getconf.php?verify=82793720_1062_82793720_1242081918_ecf6481b89582a415655bfaad82442a7&fuid=0&r=0.4403355401009321 HTTP/1.1
def getConf(uid):
#print param
url="/!house/!ranch//getconf.php?"
url+=("verify=%s" % pdict['verify'])
url+=("&fuid=%s" % uid)
import random
r=random.random()
url+=("&r=%s" % r)
req = urllib2.Request(url=host+url)
f = urllib2.urlopen(req)
#print "GET "+url
print f.msg
document=f.read()
#print f.read()
return document
#04 get host's conf
#GET /!house/!garden/getconf.php?verify=82793720_1062_82793720_1241617242_a02655ab7ab200ed717c3c307b22c30a&fuid=0&r=0.034257106482982635 HTTP/1.1
url="/!house/!ranch//getconf.php?"+param
req = urllib2.Request(url=host+url)
f = urllib2.urlopen(req)
print "GET "+url
print f.msg
document=f.read()
#print f.read().decode('utf-8').encode('gbk')
#parse host's conf
import xml.dom.minidom
def getTagText(root, tag):
node = root.getElementsByTagName(tag)
if(len(node)<=0):
return ' '
else:
node=node[0]
rc = ""
for node in node.childNodes:
if node.nodeType in ( node.TEXT_NODE, node.CDATA_SECTION_NODE):
rc = rc + node.data
return rc.encode('gbk')
hostname=""
def couldSteal(info):
if(info.find("距下次可偷")>0): #距下次可偷还有x小时
return False
return True
import re
def removeTag(xmlstr):
regex = "<(.|\n)*?>"
result = re.sub(regex,'',xmlstr)
return result
'''
偷猪
http://www.kaixin001.com/!house/!ranch//havest.php
POST DATA:
seedid 0
fuid 1023378
skey sow
foodnum 1
verify 82793720_1062_82793720_1242081918_ecf6481b89582a415655bfaad82442a7
type 1
r 0.5469534718431532
'''
'''
偷鸡蛋 POST 200 text/html http://www.kaixin001.com/!house/!ranch//havest.php
seedid 0
fuid 6200159
skey hen
foodnum 1
verify 82793720_1062_82793720_1242109445_27f6ab66fdbbb2ee24b619bcd81bb89f
type 1
r 0.17008780455216765
偷鸡蛋 http://www.kaixin001.com/!house/!ranch//havest.php
seedid 0
fuid 10203908
skey hen
foodnum 1
verify 82793720_1062_82793720_1242113554_9e5b489b7111b9810900b0447cecbe0d
type 0
r 0.648234830237925
'''
def havest(uid,document):
dom = xml.dom.minidom.parseString(document)
ac=dom.getElementsByTagName('account')[0]
name=getTagText(ac,'name')
print "进入%s的牧场..." % name
product2=dom.getElementsByTagName('product2')[0]
farms=product2.getElementsByTagName('item')
stat_all=0
stat_succ=0
#print farms[0].toxml()
#os.system('pause')
for farm in farms:
pname=getTagText(farm,'pname')
tips=getTagText(farm,'tips')
animalsid=getTagText(farm,'animalsid')
skey=getTagText(farm,'skey')
ftype=getTagText(farm,'type')
print pname,removeTag(tips)
#havest
url="/!house/!ranch//havest.php"
pdata="seedid=0"
pdata+=("&fuid=%s" % uid)
pdata+=("&skey=%s" % skey)
pdata+=("&foodnum=1")
pdata+=("verify=%s" % pdict['verify'])
pdata+=("&type=%s" % ftype)
import random
r=random.random()
if (couldSteal(tips)):
print "下手..."
req = urllib2.Request((host+url),pdata)
f = urllib2.urlopen(req)
stat_all+=1
#print "POST "+url
#print f.msg
#检查是否成功
info=f.read()
dom = xml.dom.minidom.parseString(info)
data=dom.getElementsByTagName('data')[0]
ret=getTagText(data,'ret')
if(ret.find('succ')>=0):
stat_succ+=1
print info.decode('utf-8').encode('gbk')
return name,stat_all,stat_succ
#收自家园子的菜
hostname=havest(0,document)[0]
#查看谁家的菜熟了
#GET http://www.kaixin001.com/!house/!ranch//getfriendproduct2.php?verify=82793720_1062_82793720_1242093186_1c4eb3a4db323370e09d0b85aaf86fcf&r=0.2629546015523374
url="/!house/!ranch//getfriendproduct2.php?"+param
import random
r=random.random()
url+=("&r=%s" % r)
req = urllib2.Request(url=host+url)
f = urllib2.urlopen(req)
#print f.read().decode('utf-8').encode('gbk')
#print f.read()
import json
m=f.read()
j=json.loads(m)
friends=j['steal']
stat_all,stat_succ=0,0
for friend in (friends):
uid=friend['uid']
realname=friend['realname']
print uid,realname
document=getConf(uid)
result=havest(uid,document)
stat_all+=result[1]
stat_succ+=result[2]
if stat_all>0:
stat_fail=stat_all-stat_succ
print '共下手%d次,得手%d次,失手%d次。得手率:%d%%' % (stat_all,stat_succ,stat_fail,(stat_succ*100/stat_all))
else:
print '今天没生意可做'
os.system("pause")
'''
#POST http://www.kaixin001.com/house/garden/friend_ajax.php
#verify 82793720_1062_82793720_1241712870_736ebb3ad5a6f64f8f1564cad3887b63
#fuid 0
#r 99589709
def getNeighbour(uid):
#print param
url="/house/garden/friend_ajax.php"
c=("verify=%s" % pdict['verify'])
c+=("&fuid=%s" % uid)
#Math.round((Math.random()) * 100000000)
import random
r=random.random()
r=int(r*100000000)
c+=("&r=%s" % r)
req = urllib2.Request((host+url),c)
f = urllib2.urlopen(req)
#print "GET "+url
print f.msg
document=f.read()
#print document
return document
#所有种菜的人
n=getNeighbour(0)
import json
j=json.loads(n)
nbs={}
while(not nbs.has_key(j['fuid'])):
nbs[j['fuid']]=j
n=getNeighbour(j['nextuid'])
j=json.loads(n)
#打印所有种菜的人
for k in nbs:
print k,nbs[k]['frealname']
'''