MCPcopy Create free account
hub / github.com/Urinx/WeixinBot / WeChatMsgProcessor

Class WeChatMsgProcessor

wxbot_project_py2.7/wx_handler/wechat_msg_processor.py:17–251  ·  view source on GitHub ↗

Process fetched data

Source from the content-addressed store, hash-verified

15
16
17class WeChatMsgProcessor(object):
18 """
19 Process fetched data
20 """
21
22 def __init__(self, db):
23 self.db = db
24 self.wechat = None # recieve `WeChat` class instance
25 # for call some wechat apis
26
27 # read config
28 cm = ConfigManager()
29 [self.upload_dir, self.data_dir, self.log_dir] = cm.setup_database()
30
31 def clean_db(self):
32 """
33 @brief clean database, delete table & create table
34 """
35 self.db.delete_table(Constant.TABLE_GROUP_LIST())
36 self.db.delete_table(Constant.TABLE_GROUP_USER_LIST())
37 self.db.create_table(Constant.TABLE_GROUP_MSG_LOG, Constant.TABLE_GROUP_MSG_LOG_COL)
38 self.db.create_table(Constant.TABLE_GROUP_LIST(), Constant.TABLE_GROUP_LIST_COL)
39 self.db.create_table(Constant.TABLE_GROUP_USER_LIST(), Constant.TABLE_GROUP_USER_LIST_COL)
40 self.db.create_table(Constant.TABLE_RECORD_ENTER_GROUP, Constant.TABLE_RECORD_ENTER_GROUP_COL)
41 self.db.create_table(Constant.TABLE_RECORD_RENAME_GROUP, Constant.TABLE_RECORD_RENAME_GROUP_COL)
42
43 def handle_wxsync(self, msg):
44 """
45 @brief Recieve webwxsync message, saved into json
46 @param msg Dict: webwxsync msg
47 """
48 fn = time.strftime(Constant.LOG_MSG_FILE, time.localtime())
49 save_json(fn, msg, self.log_dir, 'a+')
50
51 def handle_group_list(self, group_list):
52 """
53 @brief handle group list & saved in DB
54 @param group_list Array
55 """
56 fn = Constant.LOG_MSG_GROUP_LIST_FILE
57 save_json(fn, group_list, self.data_dir)
58 cols = [(
59 g['NickName'],
60 g['UserName'],
61 g['OwnerUin'],
62 g['MemberCount'],
63 g['HeadImgUrl']
64 ) for g in group_list]
65 self.db.insertmany(Constant.TABLE_GROUP_LIST(), cols)
66
67 def handle_group_member_list(self, group_id, member_list):
68 """
69 @brief handle group member list & saved in DB
70 @param member_list Array
71 """
72 fn = group_id + '.json'
73 save_json(fn, member_list, self.data_dir)
74 cols = [(

Callers 1

weixin_bot.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected