forked from JackonYang/renren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_info.py
74 lines (67 loc) · 2.2 KB
/
get_info.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
# -*- coding: utf-8-*-
import sys
import spider
cfg_filename='config/spider.ini'
config=None
def get_cfg_dict(section_name,has_default=True):
global config
if config is None:
import configparser
config=configparser.ConfigParser()
# global cfg_filename
config.read(cfg_filename)
try:
cfg=dict(config[section_name].items())
except KeyError:
# raise error, no such section
return None
if not has_default:
for key in config['DEFAULT'].keys():
del(cfg[key])
return cfg
def init_config():
config_account=get_cfg_dict('account')
config_repo=get_cfg_dict('repo')
repo_name=config_repo['repo_name_pre'] # table name prefix
repo_mode=config_repo['mode'] # table name prefix
user=config_account['user'] # renren account
passwd=config_account['passwd'] # renren passwd
# adopt for myself
if passwd == 'None':
passwd=None
print('config inited')
return repo_mode,repo_name,user,passwd
def run(meth,orig_id=None):
repo_mode, repo_name, user, passwd = init_config()
spider.set_repo(repo_mode)
tt = spider.spider(repo_name,user,passwd)
tt.log.setLevel(20)
my_rid, login_info = tt.login()
if my_rid is None:
print('spider login error. detail:{}'.format(login_info))
if not input('continue for test?(1/0)'):
return None
else:
my_rid='11111111'
else:
print('spider login success. rid={}'.format(my_rid))
if orig_id is None:
orig_id = my_rid
meth(tt,orig_id)
def pub_meth(obj):
return [meth for meth in dir(obj) if meth.startswith('get')]
if __name__ == '__main__':
try:
meth=getattr(spider.spider, sys.argv[1])
except AttributeError:
print('method {} not definded. method list: {}'.format(sys.argv[1], pub_meth(spider.spider)))
except IndexError:
print('input error, method is necessary. expect: python get_info method [renrenId].')
else:
if len(sys.argv) == 2:
orig_id=None
elif len(sys.argv) == 3:
orig_id=sys.argv[2]
else:
print('input error, expect: python get_info method [renrenId].')
run(meth,orig_id)