|
@@ -7,49 +7,11 @@ import time
|
|
import json
|
|
import json
|
|
import threading
|
|
import threading
|
|
|
|
|
|
-import requests
|
|
|
|
import schedule
|
|
import schedule
|
|
from tqdm import tqdm
|
|
from tqdm import tqdm
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
|
|
|
|
-from applications import PQMySQL
|
|
|
|
-from applications.decoratorApi import retryOnTimeout
|
|
|
|
-from applications import WeixinSpider
|
|
|
|
-from applications import Functions
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@retryOnTimeout()
|
|
|
|
-def bot(account_list):
|
|
|
|
- """
|
|
|
|
- 机器人
|
|
|
|
- """
|
|
|
|
- url = "https://open.feishu.cn/open-apis/bot/v2/hook/b44333f2-16c0-4cb1-af01-d135f8704410"
|
|
|
|
- headers = {"Content-Type": "application/json"}
|
|
|
|
- payload = {
|
|
|
|
- "msg_type": "interactive",
|
|
|
|
- "card": {
|
|
|
|
- "elements": [
|
|
|
|
- {
|
|
|
|
- "tag": "div",
|
|
|
|
- "text": {
|
|
|
|
- "content": "存在文章更新失败<at id=all></at>\n",
|
|
|
|
- "tag": "lark_md",
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- "tag": "div",
|
|
|
|
- "text": {
|
|
|
|
- "content": json.dumps(
|
|
|
|
- account_list, ensure_ascii=False, indent=4
|
|
|
|
- ),
|
|
|
|
- "tag": "lark_md",
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- ],
|
|
|
|
- "header": {"title": {"content": "【重点关注】", "tag": "plain_text"}},
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- requests.request("POST", url=url, headers=headers, data=json.dumps(payload), timeout=10)
|
|
|
|
|
|
+from applications import PQMySQL, WeixinSpider, Functions, log, bot
|
|
|
|
|
|
|
|
|
|
def getAccounts():
|
|
def getAccounts():
|
|
@@ -78,8 +40,6 @@ def insertEachMsg(db_client, gh_id, account_name, msg_list):
|
|
appMsgId = info.get("AppMsg", {}).get("BaseInfo", {}).get("AppMsgId", None)
|
|
appMsgId = info.get("AppMsg", {}).get("BaseInfo", {}).get("AppMsgId", None)
|
|
createTime = info.get("AppMsg", {}).get("BaseInfo", {}).get("CreateTime", None)
|
|
createTime = info.get("AppMsg", {}).get("BaseInfo", {}).get("CreateTime", None)
|
|
updateTime = info.get("AppMsg", {}).get("BaseInfo", {}).get("UpdateTime", None)
|
|
updateTime = info.get("AppMsg", {}).get("BaseInfo", {}).get("UpdateTime", None)
|
|
- # if int(time.time()) - int(updateTime) <= 20 * 60 * 60:
|
|
|
|
- # continue
|
|
|
|
Type = info.get("AppMsg", {}).get("BaseInfo", {}).get("Type", None)
|
|
Type = info.get("AppMsg", {}).get("BaseInfo", {}).get("Type", None)
|
|
detail_article_list = info.get("AppMsg", {}).get("DetailInfo", [])
|
|
detail_article_list = info.get("AppMsg", {}).get("DetailInfo", [])
|
|
if detail_article_list:
|
|
if detail_article_list:
|
|
@@ -128,7 +88,6 @@ def insertEachMsg(db_client, gh_id, account_name, msg_list):
|
|
wx_sn,
|
|
wx_sn,
|
|
json.dumps(baseInfo, ensure_ascii=False)
|
|
json.dumps(baseInfo, ensure_ascii=False)
|
|
)
|
|
)
|
|
- # print(info_tuple)
|
|
|
|
try:
|
|
try:
|
|
insert_sql = f"""
|
|
insert_sql = f"""
|
|
INSERT INTO official_articles_v2
|
|
INSERT INTO official_articles_v2
|
|
@@ -137,7 +96,15 @@ def insertEachMsg(db_client, gh_id, account_name, msg_list):
|
|
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
|
|
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
|
|
"""
|
|
"""
|
|
db_client.update(sql=insert_sql, params=info_tuple)
|
|
db_client.update(sql=insert_sql, params=info_tuple)
|
|
- print("插入成功")
|
|
|
|
|
|
+ log(
|
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
|
+ function="insertEachMsg",
|
|
|
|
+ message="插入文章数据成功",
|
|
|
|
+ data={
|
|
|
|
+ "info": info_tuple
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ )
|
|
except Exception as e:
|
|
except Exception as e:
|
|
try:
|
|
try:
|
|
update_sql = f"""
|
|
update_sql = f"""
|
|
@@ -147,9 +114,24 @@ def insertEachMsg(db_client, gh_id, account_name, msg_list):
|
|
"""
|
|
"""
|
|
db_client.update(sql=update_sql,
|
|
db_client.update(sql=update_sql,
|
|
params=(show_view_count, show_like_count, wx_sn))
|
|
params=(show_view_count, show_like_count, wx_sn))
|
|
- print("更新成功")
|
|
|
|
|
|
+ log(
|
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
|
+ function="insertEachMsg",
|
|
|
|
+ message="更新文章数据成功",
|
|
|
|
+ data={
|
|
|
|
+ "wxSn": wx_sn,
|
|
|
|
+ "likeCount": show_like_count,
|
|
|
|
+ "viewCount": show_view_count
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ )
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- print("失败-{}".format(e))
|
|
|
|
|
|
+ log(
|
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
|
+ function="insertEachMsg",
|
|
|
|
+ message="更新文章失败, 报错原因是: {}".format(e),
|
|
|
|
+ status="fail"
|
|
|
|
+ )
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
|
|
@@ -189,7 +171,20 @@ def updateEachAccount(db_client, gh_id, account_name, latest_update_time, cursor
|
|
latest_update_time=latest_update_time,
|
|
latest_update_time=latest_update_time,
|
|
cursor=next_cursor
|
|
cursor=next_cursor
|
|
)
|
|
)
|
|
|
|
+ log(
|
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
|
+ function="updateEachAccount",
|
|
|
|
+ message="账号文章更新成功",
|
|
|
|
+ data=response
|
|
|
|
+ )
|
|
else:
|
|
else:
|
|
|
|
+ log(
|
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
|
+ function="updateEachAccount",
|
|
|
|
+ message="账号文章更新失败",
|
|
|
|
+ status="fail",
|
|
|
|
+ data=response
|
|
|
|
+ )
|
|
return
|
|
return
|
|
|
|
|
|
|
|
|
|
@@ -284,20 +279,45 @@ def updateJob():
|
|
"""
|
|
"""
|
|
db_client = PQMySQL()
|
|
db_client = PQMySQL()
|
|
sub_accounts, server_accounts = getAccounts()
|
|
sub_accounts, server_accounts = getAccounts()
|
|
-
|
|
|
|
|
|
+ s_count = 0
|
|
|
|
+ f_count = 0
|
|
for sub_item in tqdm(sub_accounts):
|
|
for sub_item in tqdm(sub_accounts):
|
|
- # updateSingleJob(db_client, sub_item['ghId'])
|
|
|
|
try:
|
|
try:
|
|
updateSingleJob(db_client, sub_item['ghId'])
|
|
updateSingleJob(db_client, sub_item['ghId'])
|
|
- time.sleep(2)
|
|
|
|
|
|
+ s_count += 1
|
|
|
|
+ time.sleep(5)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- print(e)
|
|
|
|
- print("订阅号更新完成")
|
|
|
|
|
|
+ f_count += 1
|
|
|
|
+ log(
|
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
|
+ function="updateJob",
|
|
|
|
+ message="单个账号文章更新失败, 报错信息是: {}".format(e),
|
|
|
|
+ status="fail",
|
|
|
|
+ )
|
|
|
|
+ log(
|
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
|
+ function="updateJob",
|
|
|
|
+ message="订阅号更新完成",
|
|
|
|
+ data={
|
|
|
|
+ "success": s_count,
|
|
|
|
+ "fail": f_count
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ if f_count / (s_count + f_count) > 0.3:
|
|
|
|
+ bot(
|
|
|
|
+ title="订阅号超过 30% 的账号更新失败",
|
|
|
|
+ detail={
|
|
|
|
+ "success": s_count,
|
|
|
|
+ "fail": f_count,
|
|
|
|
+ "failRate": f_count / (s_count + f_count)
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
|
|
for sub_item in tqdm(server_accounts):
|
|
for sub_item in tqdm(server_accounts):
|
|
try:
|
|
try:
|
|
updateSingleJob(db_client, sub_item['ghId'])
|
|
updateSingleJob(db_client, sub_item['ghId'])
|
|
- time.sleep(2)
|
|
|
|
|
|
+ time.sleep(5)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(e)
|
|
print(e)
|
|
|
|
|
|
@@ -325,7 +345,10 @@ def checkJob():
|
|
fail_list.append(sub_item)
|
|
fail_list.append(sub_item)
|
|
if fail_list:
|
|
if fail_list:
|
|
try:
|
|
try:
|
|
- bot(fail_list)
|
|
|
|
|
|
+ bot(
|
|
|
|
+ title="日常报警, 存在账号更新失败",
|
|
|
|
+ detail=fail_list
|
|
|
|
+ )
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print("Timeout Error: {}".format(e))
|
|
print("Timeout Error: {}".format(e))
|
|
|
|
|
|
@@ -342,10 +365,9 @@ def job_with_thread(job_func):
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
|
|
|
- # updateJob()
|
|
|
|
- # schedule.every().day.at("20:50").do(job_with_thread, updateJob)
|
|
|
|
- #
|
|
|
|
- schedule.every().day.at("22:30").do(job_with_thread, checkJob)
|
|
|
|
|
|
+ schedule.every().day.at("20:50").do(job_with_thread, updateJob)
|
|
|
|
+
|
|
|
|
+ schedule.every().day.at("22:00").do(job_with_thread, checkJob)
|
|
|
|
|
|
while True:
|
|
while True:
|
|
schedule.run_pending()
|
|
schedule.run_pending()
|