-
Notifications
You must be signed in to change notification settings - Fork 18
/
u115_bot.py
122 lines (105 loc) · 3.12 KB
/
u115_bot.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import logging
import getopt
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from u115_api import u115_api
arg_user = None
arg_pass = None
arg_sleeptime = 120
arg_taskfile = None
def readtask():
global arg_taskfile
return open(arg_taskfile).readlines()
def update_task(context):
#lock
return open('task.txt', 'w').writelines(context)
def update_task_process(context):
return open('taskprocess.txt', 'a').write(context + '\n')
def update_task_success(context):
return open('tasksuccess.txt', 'a').write(context + '\n')
def monitor():
global arg_pass
global arg_user
global arg_sleeptime
global arg_taskfile
u115 = u115_api()
u115.login(arg_user, arg_pass)
while True:
try:
ret, result = u115.auto_make_share_link()
for res in result:
update_task_success('http://115.com/lb/%s ---- %s' % (res['Code'], res['Name']))
if 15 > u115.ret_current_bt_task_count():
task_list = readtask()
if len(task_list) == 0:
logging.info('没有任务文件...zZZ'.decode('utf-8'))
else:
i = task_list[0]
task_list.pop(0)
update_task(task_list)
if not i.startswith("http"):
continue
update_task_process(i)
u115.add_http_task(i)
continue
time.sleep(arg_sleeptime)
except KeyboardInterrupt:
break
except:
import traceback
print traceback.print_exc()
time.sleep(arg_sleeptime * 10)
u115 = u115_api()
u115.login(arg_user, arg_pass)
def Usage():
print '115Bot usage:'
print '-u, --user: 115 account login user'
print '-p, --pass: 115 account login pass'
print '-f, --file: task list file\n'
print '-h, --help: print help message.'
print '-v, --version: print script version'
def Version():
print '115Bot ver 0.1'
def main(argv):
global arg_pass
global arg_user
global arg_sleeptime
global arg_taskfile
try:
opts, args = getopt.getopt(argv[1:], 'u:p:f:v:h', ['user=', 'pass=', 'file=', 'help', 'version'])
except getopt.GetoptError, err:
print str(err)
Usage()
sys.exit(2)
for o, a in opts:
if o in ('-h', '--help'):
Usage()
sys.exit(1)
elif o in ('-v', '--version'):
Version()
sys.exit(0)
elif o in ('-f', '--file'):
arg_taskfile = a
elif o in ('-u', '--user'):
arg_user = a
elif o in ('-p', '--pass'):
arg_pass = a
else:
print 'unhandled option'
sys.exit(1)
if arg_taskfile is None:
print 'missing arg -f'
sys.exit(2)
if arg_user is None:
print 'missing arg -u'
sys.exit(2)
if arg_pass is None:
print 'missing arg -p'
sys.exit(2)
monitor()
if __name__ == '__main__':
main(sys.argv)