def check_schedule_task(self): # update group member list at 00:00 am every morning t = time.localtime() if t.tm_hour == 0 and t.tm_min <= 1: # update group member Log.debug('update group member list everyday') self.db.delete_table(Constant.TABLE_GROUP_LIST()) self.db.delete_table(Constant.TABLE_GROUP_USER_LIST()) self.db.create_table(Constant.TABLE_GROUP_LIST(), Constant.TABLE_GROUP_LIST_COL) self.db.create_table(Constant.TABLE_GROUP_USER_LIST(), Constant.TABLE_GROUP_USER_LIST_COL) self.wechat.fetch_group_contacts()
def clean_db(self): """ @brief clean database, delete table & create table """ self.db.delete_table(Constant.TABLE_GROUP_LIST()) self.db.delete_table(Constant.TABLE_GROUP_USER_LIST()) self.db.create_table(Constant.TABLE_GROUP_MSG_LOG, Constant.TABLE_GROUP_MSG_LOG_COL) self.db.create_table(Constant.TABLE_GROUP_LIST(), Constant.TABLE_GROUP_LIST_COL) self.db.create_table(Constant.TABLE_GROUP_USER_LIST(), Constant.TABLE_GROUP_USER_LIST_COL) self.db.create_table(Constant.TABLE_RECORD_ENTER_GROUP, Constant.TABLE_RECORD_ENTER_GROUP_COL) self.db.create_table(Constant.TABLE_RECORD_RENAME_GROUP, Constant.TABLE_RECORD_RENAME_GROUP_COL)
def group_member_list(g_id): """ @brief list group member @param g_id String """ result = wechat.db.select(Constant.TABLE_GROUP_USER_LIST(), 'RoomID', g_id) return jsonify({'count': len(result), 'member': result})
def group_member_list(g_id): """ @brief list group member @param g_id String """ result = wechat.db.select(Constant.TABLE_GROUP_USER_LIST(), 'RoomID', g_id) j = {'count': len(result), 'member': result} return flask.Response(json.dumps(j), mimetype='application/json')
def handle_group_member_change(self, group_id, member_list): """ @brief handle group member changes & saved in DB @param group_id Dict @param member_list Dict """ self.db.delete(Constant.TABLE_GROUP_USER_LIST(), "RoomID", group_id) self.handle_group_member_list(group_id, member_list)
def handle_group_member_list(self, group_id, member_list): """ @brief handle group member list & saved in DB @param member_list Array """ fn = group_id + '.json' save_json(fn, member_list, self.data_dir) cols = [(group_id, m['UserName'], m['NickName'], m['DisplayName'], m['AttrStatus']) for m in member_list] self.db.insertmany(Constant.TABLE_GROUP_USER_LIST(), cols)