-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
131 lines (106 loc) · 3.76 KB
/
test.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
#coding:utf-8
'''
Created on 2016年11月5日
@author: superxiaoxiong
'''
from log import logger
from downloader import DownLoader
import requests
import net
import sys
import threading
from auth import LoginWanpan
import pcs
import tool
import os
import config
import urllib
def test_log():
logger.info('test')
def test_download():
req, bdstoken = test_login()
#url = url
dirname=r'e:/tmppic'
filename='scorpion.mp4'
#req = requests.Session()
url = 'http://pcs.baidu.com/rest/2.0/pcs/file?path=' + urllib.quote('/Scorpion.S03E08.720p.HDTV.NCARBBS.X264-DIMENSION.chs.eng') + '&method=download&app_id=266719'
downloader = DownLoader(req, url, dirname, filename)
t = threading.Thread(target=downloader.run,args=())
t.setDaemon(True)
t.start()
while True:
if not t.is_alive():
logger.info('download finished!' + filename)
sys.exit()
try:
cmd = raw_input(u'请输入')
except (KeyboardInterrupt, SystemExit):
print u'quit '
logger.info('test quit ')
downloader.pause()
sys.exit(0)
else:
cmd = cmd.decode(sys.getfilesystemencoding())
if cmd == 'pause':
print u'pause '
logger.info('test pause')
downloader.pause()
elif cmd == 'load':
print u'load '
logger.info('test load ')
downloader = DownLoader(req, url, dirname, filename)
t = threading.Thread(target=downloader.run,args=())
t.setDaemon(True)
t.start()
def test_simple_requests():
url = 'https://c.pcs.baidu.com/rest/2.0/pcs/file?metho'
req = requests.Session()
res = net.simple_request(url, req)
if res.ok:
print res.headers
print res.request.headers
print res.status_code
print res.reason
else:
print 'no'
def test_login():
login_wanpan = LoginWanpan()
token = login_wanpan.load_auth()
if os.path.exists('./cookies'):
cookies = tool.load_cookies_from_lwp('./cookies')
print cookies
print token
req = requests.Session()
req.cookies = cookies
bdstoken = login_wanpan.get_bdstoken(req)
return req, bdstoken
else:
return login_wanpan.run()
#req = login_wanpan.run()
def qr_check():
import re
res = {"errInfo":{ "no": "0" }, "data": { "codeString" : "jxG7f06c1fe8571e21f022314d54301417e776a9807b9017bc7", "vcodetype" : "4ea5vlvQPdjy2odW8u8ETdqBkGiN3YfP777DbFPoig9e0h9NfRN7s4lOqMzP42a61LAD5WR4EEJNtFqfa9AFRkqiCCCDXOxX8491", "userid" : "", "mobile" : "" }}
res = str(res)
logger.debug(res)
print res
#\s*"vcodetype"\s*:\s*"(\w*)"
pm = re.search(r'\'codeString\'\s*:\s*\'(\w*)\',\s*\'vcodetype\'\s*:\s*\'(\w*)\'', res)
if pm:
codeString = pm.group(1)
vcodetype = pm.group(2)
print codeString,vcodetype
def key_check():
import re
res = r'-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtkCrB468BmyT\/dsXYYjC5hYqF\nKD3nO5SGUu33MH4Iw++uUyW5I8IppgXNWcXqvMrUyxuWg9Z\/ryRevCm4P4zMpyhs\nMpBOi81s6H8L8J6OeTyC3b4pkkHDVFPhZVBGLjMb3xB+KGB3o0rV5R1ohXDwooEN\nqHKmMROwGoaQBHk\/mQIDAQAB\n-----END PUBLIC KEY-----\n'
public_key = re.search(r'-----BEGIN PUBLIC KEY-----\n(.*?)-----END PUBLIC KEY-----\n', res)
print public_key.group(1)
def test_get_dlink(req, bdstoken, path):
pcs.get_metas(req, bdstoken, path)
#test_log()
test_download()
#key_check()
#req, bdstoken = test_login()
'''
test_get_dlink(req, bdstoken, u'/系统')
test_get_dlink(req, bdstoken, '/forensic.7z')
'''