|
@@ -12,12 +12,12 @@ from tqdm import tqdm
|
|
|
from datetime import datetime
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
-
|
|
|
from applications import PQMySQL, WeixinSpider, Functions, log, bot, aiditApi
|
|
|
from applications.const import updatePublishedMsgTaskConst
|
|
|
|
|
|
ARTICLE_TABLE = "official_articles_v2"
|
|
|
const = updatePublishedMsgTaskConst()
|
|
|
+spider = WeixinSpider()
|
|
|
|
|
|
|
|
|
def get_account_using_status():
|
|
@@ -586,6 +586,54 @@ def get_article_detail_job():
|
|
|
)
|
|
|
|
|
|
|
|
|
+def monitor():
|
|
|
+ """
|
|
|
+ 监控任务, 监测周期为3天,监测文章是否被违规,若监测到违规文章,则进行告警
|
|
|
+ :return:
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ db_client = PQMySQL()
|
|
|
+ except Exception as e:
|
|
|
+ error_msg = traceback.format_exc()
|
|
|
+ bot(
|
|
|
+ title="监控任务连接数据库失败",
|
|
|
+ detail={
|
|
|
+ "job": "monitor",
|
|
|
+ "error": e,
|
|
|
+ "msg": error_msg
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return
|
|
|
+
|
|
|
+ now_time = int(time.time())
|
|
|
+ monitor_start_timestamp = now_time - const.MONITOR_PERIOD
|
|
|
+ select_sql = f"""
|
|
|
+ SELECT ghId, accountName, title, ContentUrl, wx_sn
|
|
|
+ FROM {ARTICLE_TABLE}
|
|
|
+ WHERE publish_timestamp >= {monitor_start_timestamp};
|
|
|
+ """
|
|
|
+ article_list = db_client.select(select_sql)
|
|
|
+ for article in tqdm(article_list, desc="monitor article list"):
|
|
|
+ gh_id = article[0]
|
|
|
+ account_name = article[1]
|
|
|
+ title = article[2]
|
|
|
+ url = article[3]
|
|
|
+ wx_sn = article[4]
|
|
|
+ response = spider.get_article_text(url)
|
|
|
+ response_code = response['code']
|
|
|
+ if response_code == const.ARTICLE_ILLEGAL_CODE:
|
|
|
+ bot(
|
|
|
+ title="文章违规告警",
|
|
|
+ detail={
|
|
|
+ "ghId": gh_id,
|
|
|
+ "accountName": account_name,
|
|
|
+ "title": title,
|
|
|
+ "wx_sn": wx_sn
|
|
|
+ },
|
|
|
+ mention=False
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def main():
|
|
|
"""
|
|
|
main
|
|
@@ -599,7 +647,7 @@ def main():
|
|
|
if __name__ == '__main__':
|
|
|
parser = ArgumentParser()
|
|
|
parser.add_argument("--run_task",
|
|
|
- help="update: update_job, check: check_job, detail: get_article_detail_job")
|
|
|
+ help="update: update_job, check: check_job, detail: get_article_detail_job, monitor: monitor")
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
if args.run_task:
|
|
@@ -611,8 +659,9 @@ if __name__ == '__main__':
|
|
|
check_job()
|
|
|
case "detail":
|
|
|
get_article_detail_job()
|
|
|
+ case "monitor":
|
|
|
+ monitor()
|
|
|
case _:
|
|
|
print("No such task, input update: update_job, check: check_job, detail: get_article_detail_job")
|
|
|
else:
|
|
|
main()
|
|
|
-
|