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 group_list(): """ @brief list groups """ result = wechat.db.select(Constant.TABLE_GROUP_LIST()) j = {'count': len(result), 'group': result} return flask.Response(json.dumps(j), mimetype='application/json')
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 handle_group_list(self, group_list): """ @brief handle group list & saved in DB @param group_list Array """ fn = Constant.LOG_MSG_GROUP_LIST_FILE save_json(fn, group_list, self.data_dir) cols = [(g['NickName'], g['UserName'], g['OwnerUin'], g['MemberCount'], g['HeadImgUrl']) for g in group_list] self.db.insertmany(Constant.TABLE_GROUP_LIST(), cols)
def group_list(): """ @brief list groups """ result = wechat.db.select(Constant.TABLE_GROUP_LIST()) return jsonify({'count': len(result), 'group': result})