-
Notifications
You must be signed in to change notification settings - Fork 38
/
cli.py
executable file
·115 lines (92 loc) · 2.55 KB
/
cli.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
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
命令行工具
用法: ./cli.py -o http://xxx.com/xxx.tar.gz
例子:
开始离线下载
./cli.py -o http://xxx.com/xxx.tar.gz
./cli.py --offline="http://xxx.com/xxx.tar.gz"
-h, --help 查看帮助
-o, --offline 开始离线下载
-t, --task 查看离线下载队列
360yunpan - 360YunPan Command-line tools, support: Linux Mac Windows
Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php
Project home:
https://github.com/logbird/360yunpan
Version: 1.0.0
@Author [email protected]
"""
import sys
import getopt
import urllib
import urllib2
import cookielib
import time
import random
import hashlib
import json
import re
import os
reload(sys)
sys.setdefaultencoding("utf-8")
import utilsYunPan
from loginYunPan import loginYunPan
from dirYunPan import dirYunPan
from downloadYunPan import downloadYunPan
from downloadYunPan import downloadManager
conf = {
}
def usage():
print """
用法: ./cli.py -o http://xxx.com/xxx.tar.gz
例子:
开始离线下载
./cli.py -o http://xxx.com/xxx.tar.gz
./cli.py --offline="http://xxx.com/xxx.tar.gz"
-h, --help 查看帮助
-o, --offline 开始离线下载
-t, --task 查看离线下载队列
"""
sys.exit()
def login(user, pwd):
login = loginYunPan()
userinfo = login.run(user, pwd)
return login, userinfo
def offlineDownload(loginObj, url):
dir = dirYunPan('/')
result = dir.offlineDownload("http://todeer.sinaapp.com/include/lib/js/common_tpl.js");
print result['task_id']
def offlineList(loginObj):
dir = dirYunPan('/')
result = dir.offlineList();
task_list = {}
if result.has_key('offline_task_list'):
task_list = result['offline_task_list']
for i in task_list:
print "%s\t%s\t%s" % (i['status'], i['task_id'], i['url'])
def runCommand(conf, user, pwd):
try:
opts, args = getopt.getopt(sys.argv[1:],'o:th:',['offline=', 'task','help'])
except getopt.GetoptError:
usage()
sys.exit()
loginObj, user = login(user, pwd)
for o, a in opts:
if o in ("-h", "--help"):
usage()
elif o in ("-o", "--offline"):
offlineDownload(loginObj, a)
elif o in ("-t", "--task"):
offlineList(loginObj)
else:
#usage()
pass
return conf
if __name__ == '__main__':
username = 'username'
password = 'password'
# 初始化 命令行参数
conf = runCommand(conf, username, password)
sys.exit()