-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.py
84 lines (78 loc) · 2.64 KB
/
run.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
# -*- coding: utf-8 -*-
# Original author of bcloud is LiuLang <gsushzhsosgsu@gmail.com>
# bcloud-cl is a command line bcloud created by Caasiu
# Use of this source code is governed by GPLv3 license that can be found
# in http://www.gnu.org/licenses/gpl-3.0.html
import os
import json
import auth
#初始化参数
cookie={}
tokens={}
username=''
password=''
verifycode=''
codeString=''
pubkey=''
rsakey=''
cookie = auth.get_BAIDUID()
token = auth.get_token(cookie)
tokens['token'] = token
ubi = auth.get_UBI(cookie,tokens)
cookie = auth.add_cookie(cookie,ubi,['UBI','PASSID'])
key_data = auth.get_public_key(cookie,tokens)
pubkey = key_data['pubkey']
rsakey = key_data['key']
username = raw_input('username:')
password = raw_input('password:')
password_enc = auth.RSA_encrypt(pubkey, password)
err_no,query = auth.post_login(cookie,tokens,username,password_enc,rsakey)
if err_no == 0:
auth_cookie = query
bdstoken = auth.get_bdstoken(auth_cookie)
tokens['bdstoken'] = bdstoken
user_dir = os.path.join(os.path.abspath('.'), username)
if not os.path.isdir(user_dir):
os.mkdir(user_dir)
auth_data_path = os.path.join(user_dir, 'auth_data.txt')
auth_data = [auth_cookie,tokens]
with open(auth_data_path, 'w') as f:
json.dump(auth_data, f)
print(auth_cookie)
print(tokens)
elif err_no == 4:
print('your password is incorrect')
elif err_no == 257:
vcodetype = query['vcodetype']
codeString = query['codeString']
auth.get_signin_vcode(cookie, codeString)
while True:
ans = raw_input('refresh vcode? [y/N]: ')
if ans == 'N' or ans == 'n':
break
codeString = auth.refresh_vcode(cookie,tokens,vcodetype)
verifycode = raw_input('input verifycode here:')
if verifycode:
err_no,query = auth.post_login(cookie,tokens,username,password_enc,rsakey,verifycode,codeString)
if err_no == 0:
temp_cookie = query
auth_cookie,bdstoken = auth.get_bdstoken(temp_cookie)
tokens['bdstoken'] = bdstoken
user_dir = os.path.join(os.path.abspath('.'), username)
if not os.path.isdir(user_dir):
os.mkdir(user_dir)
auth_data_path = os.path.join(user_dir, 'auth_data.txt')
auth_data = [auth_cookie,tokens]
with open(auth_data_path, 'w') as f:
json.dump(auth_data, f)
print(auth_cookie)
print(tokens)
else:
print('try again')
else:
print('vcode characters must be 4, try again')
elif err_no == -1:
print('Fail to login unknow error')
else:
print(err_no)
print('open the error file to solve the issue')