Skip to content

Commit 4282a34

Browse files
committed
add kuaipan auto sign
1 parent 365b7ad commit 4282a34

File tree

3 files changed

+132
-3
lines changed

3 files changed

+132
-3
lines changed

KuaiPan/Kuaipan_sign.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import urllib,sys
4+
import urllib2
5+
import cookielib
6+
import json
7+
from mail import Mail
8+
9+
#作用:快盘自动签到程序
10+
class Login_kp:
11+
def __init__(self):
12+
cj = cookielib.CookieJar()
13+
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
14+
urllib2.install_opener(self.opener)
15+
self.opener.addheaders = [('User-agent', 'IE')]
16+
17+
def login(self, username, password):
18+
#首先访问主页,获取必要的cookie
19+
req1 = urllib2.Request('https://www.kuaipan.cn')
20+
try:
21+
self.opener.open(req1)
22+
except Exception:
23+
print(u'预加载失败:网络连接错误!')
24+
return False
25+
26+
#try to login
27+
loginUrl = 'https://www.kuaipan.cn/index.php?ac=account&op=login'
28+
data = urllib.urlencode({'username':username, 'userpwd':password,'isajax':'yes'})
29+
req = urllib2.Request(loginUrl, data)
30+
try:
31+
response = self.opener.open(req)
32+
resHtml = response.read()
33+
resJson = json.loads(resHtml)
34+
if resJson['state'] == '0':
35+
if resJson['errcode'] == 'checkemailcode_2':
36+
print u'email is not exist'
37+
return False
38+
elif resJson['errcode'] == 'account_api_login_accountNotMatch':
39+
print u'account not match'
40+
return False
41+
else:
42+
print u'login failed. errcode:',resJson['errcode']
43+
return False
44+
45+
except Exception:
46+
s=sys.exc_info()
47+
print "Error '%s' happened on line %d" % (s[1],s[2].tb_lineno)
48+
return False
49+
50+
print(u'%s login succeed...' % username),
51+
return True
52+
53+
def logout(self):
54+
url = 'http://www.kuaipan.cn/index.php?ac=account&op=logout'
55+
req = urllib2.Request(url)
56+
fd = self.opener.open(req)
57+
fd.close()
58+
59+
def sign(self):
60+
url = 'http://www.kuaipan.cn/index.php?ac=common&op=usersign'
61+
req = urllib2.Request(url)
62+
fd = self.opener.open(req)
63+
signReturnJson = fd.read()
64+
sign_js = json.loads(signReturnJson)
65+
if sign_js['state'] == -102:
66+
print(u"has signed today!")
67+
Mail().SendMail(u'快盘签到',["[email protected]"], u"今日已经在其他地方签到", "fyi.")
68+
elif sign_js['state'] == 1:
69+
o = u"签到成功! 获得积分:%d,总积分:%d;获得空间:%dM\n" % (sign_js['increase'], sign_js['status']['points'], sign_js['rewardsize'])
70+
print o
71+
Mail().SendMail(u'快盘签到',["[email protected]"], u"签到成功", o)
72+
else:
73+
print(u"sign failed!")
74+
fd.close()
75+
76+
if __name__ == '__main__':
77+
l = Login_kp()
78+
if l.login('email', 'pwd') == False:
79+
exit(1)
80+
l.sign()

KuaiPan/mail.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
# -*- coding: gbk -*-
3+
from __future__ import unicode_literals
4+
import smtplib
5+
from email.mime.text import MIMEText
6+
7+
class Mail():
8+
"""
9+
发送邮件
10+
"""
11+
12+
#设置服务器,用户名、口令以及邮箱的后缀
13+
mail_host = "smtp.163.com"
14+
mail_user = "[email protected]"
15+
mail_pass = "autorun"
16+
mail_postfix = "163.com"
17+
18+
def SendMail(self,fromWho, toList, title, content, fromAddress=None):
19+
'''
20+
toList:发给谁
21+
fromAddtress:来自于
22+
title:主题
23+
content:内容
24+
Mail().SendMail(["[email protected],[email protected]"], "title", "content"):
25+
'''
26+
me = "%s<[email protected]>" % fromWho
27+
if fromAddress is None:
28+
fromAddress = me
29+
30+
msg = MIMEText(content)
31+
msg['Subject'] = title
32+
msg['From'] = fromAddress
33+
msg['To'] = ";".join(toList)
34+
try:
35+
s = smtplib.SMTP()
36+
s.connect(self.mail_host)
37+
s.login(self.mail_user, self.mail_pass)
38+
s.sendmail(me, toList, msg.as_string())
39+
s.close()
40+
return True
41+
except Exception, e:
42+
print str(e)
43+
return False
44+
45+
if __name__ == "__main__":
46+
if Mail().SendMail('qianlifeng',["[email protected]"], "title", "content"):
47+
print "发送成功"
48+
else:
49+
print "发送失败"

Notification/mail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class Mail():
1515
mail_pass = "autorun"
1616
mail_postfix = "163.com"
1717

18-
def SendMail(self, toList, title, content, fromAddress=None):
18+
def SendMail(self,fromWho, toList, title, content, fromAddress=None):
1919
'''
2020
toList:发给谁
2121
fromAddtress:来自于
2222
title:主题
2323
content:内容
2424
Mail().SendMail(["[email protected],[email protected]"], "title", "content"):
2525
'''
26-
me = "AutorunForScott<[email protected]>"
26+
me = "%s<[email protected]>" % fromWho
2727
if fromAddress is None:
2828
fromAddress = me
2929

@@ -43,7 +43,7 @@ def SendMail(self, toList, title, content, fromAddress=None):
4343
return False
4444

4545
if __name__ == "__main__":
46-
if Mail().SendMail(["qianlf2008@163.com,test@test.com"], "title", "content"):
46+
if Mail().SendMail('qianlifeng',["[email protected]"], "title", "content"):
4747
print "发送成功"
4848
else:
4949
print "发送失败"

0 commit comments

Comments
 (0)