def ob_all(self): """Observe all objects in watch list. No paras needed. It automatically fetches data from database, then loop through all items. Args: Returns: success: bool """ db = DbOperator() success, watch_list = db.fetch_all_article() if not success: logger.warning("ob_all find nothing") return False for item in watch_list: article_id = item['article_id'] URL = item['URL'] status = item['status'] start_date = item['start_date'] if _out_of_date(start_date): # 超出30天的观察目标,停止观察 backup_addr = item['backup_addr'] update_article_status(article_id, False, backup_addr) logger.info( "move article to archive: " + " ".join(map(str, [article_id, status, start_date]))) continue else: if status == 0: # 初次观察,需要制作备份 self.q.put(article_id=article_id, url=URL, download=True, block=True, timeout=1) elif status == 1: # 正常观察期,不再制作备份 self.q.put(article_id=article_id, url=URL, download=False, block=True, timeout=1) else: logger.error("Unknow article status: " + " ".join(map(str, [article_id, URL, status]))) return True
def _admin_list(self, msg): user = msg.source if user not in ADMIN_LIST: return "非管理员账号,无法执行admin命令" db = DbOperator() success, result = db.fetch_all_article() if not success: logger.info("_admin_list fetch 0") return "admin-list 查询失败,结果为空" output = [] for item in result: output.append(item['article_id']) output.append(item['URL']) output.append(item['open_id']) output.append(item['backup_addr']) output.append(item['start_date']) output.append(item['status']) output.append('--------') return "\n".join(map(str, output))