forked from yueyoum/renren-relationship
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
54 lines (38 loc) · 1.08 KB
/
utils.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
# -*- coding: utf-8 -*-
import functools
import gevent
class TooLong(Exception):
pass
def retry(times=2):
def deco(func):
@functools.wraps(func)
def wraps(*args, **kwargs):
for t in range(times):
try:
return func(*args, **kwargs)
except TooLong:
gevent.sleep(1)
continue
print 'try %d times, but still failure' % times
return []
return wraps
return deco
def gtimeout(t=10, mute=False):
def deco(func):
@functools.wraps(func)
def wrap(*args, **kwargs):
try:
with gevent.Timeout(t, TooLong):
return func(*args, **kwargs)
except TooLong:
if mute:
return []
raise
return wrap
return deco
def get_accounts():
with open('account', 'r') as f:
data = f.readlines()
email = data[0].rstrip('\n')
password = data[1].rstrip('\n')
return email, password