|
| 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() |
0 commit comments