|
@@ -294,61 +294,102 @@ class UpdatePublishedArticlesReadDetail(object):
|
|
|
更新单个账号的文章
|
|
|
"""
|
|
|
gh_id = account_info['ghId']
|
|
|
+ account_name = account_info['name']
|
|
|
select_sql = f"""
|
|
|
SELECT published_url, publish_timestamp, root_source_id_list, create_timestamp
|
|
|
FROM long_articles_published_trace_id
|
|
|
- WHERE gh_id = '{gh_id}' AND publish_timestamp> UNIX_TIMESTAMP(DATE_SUB('{run_date}', INTERVAL 3 DAY));
|
|
|
+ WHERE gh_id = '{gh_id}' AND publish_timestamp > UNIX_TIMESTAMP(DATE_SUB('{run_date}', INTERVAL 3 DAY));
|
|
|
"""
|
|
|
result = self.long_articles_db_client.fetch(select_sql, cursor_type=DictCursor)
|
|
|
for article in result:
|
|
|
published_url = article['published_url']
|
|
|
article_info = spider.get_article_text(content_link=published_url, is_cache=False, is_count=True)
|
|
|
response_code = article_info['code']
|
|
|
- if response_code == 0:
|
|
|
- response_data = article_info['data']['data']
|
|
|
- title = response_data['title']
|
|
|
- article_url = response_data['content_link']
|
|
|
- show_view_count = response_data['view_count']
|
|
|
- show_like_count = response_data['like_count']
|
|
|
- show_zs_count = 0
|
|
|
- show_pay_count = 0
|
|
|
- wx_sn = article_url.split("&sn=")[1].split("&")[0] if article_url else None
|
|
|
- app_msg_id = article_url.split("&mid=")[1].split("&")[0] if article_url else None
|
|
|
- status = account_info['using_status']
|
|
|
- info_tuple = (
|
|
|
- gh_id,
|
|
|
- account_info['name'],
|
|
|
- app_msg_id,
|
|
|
- title,
|
|
|
- "9",
|
|
|
- article['create_timestamp'],
|
|
|
- response_data['update_timestamp'],
|
|
|
- None,
|
|
|
- response_data['item_index'],
|
|
|
- response_data['content_link'],
|
|
|
- None,
|
|
|
- None,
|
|
|
- None,
|
|
|
- None,
|
|
|
- None,
|
|
|
- response_data.get("is_original", None),
|
|
|
- None,
|
|
|
- None,
|
|
|
- show_view_count,
|
|
|
- show_like_count,
|
|
|
- show_zs_count,
|
|
|
- show_pay_count,
|
|
|
- wx_sn,
|
|
|
- None,
|
|
|
- functions.str_to_md5(title),
|
|
|
- status
|
|
|
- )
|
|
|
- self.insert_each_article(
|
|
|
- info_tuple=info_tuple,
|
|
|
- show_view_count=show_view_count,
|
|
|
- show_like_count=show_like_count,
|
|
|
- wx_sn=wx_sn
|
|
|
- )
|
|
|
+ match response_code:
|
|
|
+ case const.ARTICLE_SUCCESS_CODE:
|
|
|
+ response_data = article_info['data']['data']
|
|
|
+ title = response_data['title']
|
|
|
+ article_url = response_data['content_link']
|
|
|
+ show_view_count = response_data['view_count']
|
|
|
+ show_like_count = response_data['like_count']
|
|
|
+ show_zs_count = 0
|
|
|
+ show_pay_count = 0
|
|
|
+ wx_sn = article_url.split("&sn=")[1].split("&")[0] if article_url else None
|
|
|
+ app_msg_id = article_url.split("&mid=")[1].split("&")[0] if article_url else None
|
|
|
+ status = account_info['using_status']
|
|
|
+ info_tuple = (
|
|
|
+ gh_id,
|
|
|
+ account_info['name'],
|
|
|
+ app_msg_id,
|
|
|
+ title,
|
|
|
+ "9",
|
|
|
+ article['create_timestamp'],
|
|
|
+ response_data['update_timestamp'],
|
|
|
+ None,
|
|
|
+ response_data['item_index'],
|
|
|
+ response_data['content_link'],
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ response_data.get("is_original", None),
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ show_view_count,
|
|
|
+ show_like_count,
|
|
|
+ show_zs_count,
|
|
|
+ show_pay_count,
|
|
|
+ wx_sn,
|
|
|
+ None,
|
|
|
+ functions.str_to_md5(title),
|
|
|
+ status
|
|
|
+ )
|
|
|
+ self.insert_each_article(
|
|
|
+ info_tuple=info_tuple,
|
|
|
+ show_view_count=show_view_count,
|
|
|
+ show_like_count=show_like_count,
|
|
|
+ wx_sn=wx_sn
|
|
|
+ )
|
|
|
+ case const.ARTICLE_DELETE_CODE:
|
|
|
+ log(
|
|
|
+ task="updatePublishedMsgDaily",
|
|
|
+ function="update_account_by_aigc",
|
|
|
+ message="文章被删除",
|
|
|
+ data={
|
|
|
+ "ghId": gh_id,
|
|
|
+ "publishedUrl": published_url
|
|
|
+ }
|
|
|
+ )
|
|
|
+ case const.ARTICLE_ILLEGAL_CODE:
|
|
|
+ error_detail = article_info.get("msg")
|
|
|
+ insert_sql = f"""
|
|
|
+ INSERT IGNORE INTO illegal_articles
|
|
|
+ (gh_id, account_name, title, wx_sn, publish_date, illegal_reason)
|
|
|
+ VALUES
|
|
|
+ (%s, %s, %s, %s, %s, %s);
|
|
|
+ """
|
|
|
+ affected_rows = self.long_articles_db_client.save(
|
|
|
+ query=insert_sql,
|
|
|
+ params=(gh_id, account_name, title, wx_sn, publish_date, error_detail),
|
|
|
+ )
|
|
|
+ if affected_rows:
|
|
|
+ bot(
|
|
|
+ title="文章违规告警",
|
|
|
+ detail={
|
|
|
+ "account_name": account_name,
|
|
|
+ "gh_id": gh_id,
|
|
|
+ "title": title,
|
|
|
+ "wx_sn": wx_sn.decode("utf-8"),
|
|
|
+ "publish_date": str(publish_date),
|
|
|
+ "error_detail": error_detail,
|
|
|
+ },
|
|
|
+ mention=False
|
|
|
+ )
|
|
|
+ aiditApi.delete_articles(
|
|
|
+ gh_id=gh_id,
|
|
|
+ title=title
|
|
|
+ )
|
|
|
|
|
|
def get_account_info(self, gh_id: str) -> int:
|
|
|
"""
|
|
@@ -494,7 +535,7 @@ class UpdatePublishedArticlesReadDetail(object):
|
|
|
subscription_accounts = [i for i in account_list if i['account_type'] in const.SUBSCRIBE_TYPE_SET]
|
|
|
success_count = 0
|
|
|
fail_count = 0
|
|
|
- for account in tqdm(subscription_accounts):
|
|
|
+ for account in tqdm(subscription_accounts[:10]):
|
|
|
try:
|
|
|
self.process_single_account(account_info=account, run_date=biz_date)
|
|
|
success_count += 1
|
|
@@ -525,14 +566,14 @@ class UpdatePublishedArticlesReadDetail(object):
|
|
|
"failRate": fail_count / (success_count + fail_count)
|
|
|
}
|
|
|
)
|
|
|
- bot(
|
|
|
- title="更新每日发布文章任务完成通知",
|
|
|
- detail={
|
|
|
- "msg": "订阅号更新完成",
|
|
|
- "finish_time": datetime.today().__str__()
|
|
|
- },
|
|
|
- mention=False
|
|
|
- )
|
|
|
+ # bot(
|
|
|
+ # title="更新每日发布文章任务完成通知",
|
|
|
+ # detail={
|
|
|
+ # "msg": "订阅号更新完成",
|
|
|
+ # "finish_time": datetime.today().__str__()
|
|
|
+ # },
|
|
|
+ # mention=False
|
|
|
+ # )
|
|
|
|
|
|
# 服务号
|
|
|
server_accounts = [i for i in account_list if i['account_type'] == const.SERVICE_TYPE]
|
|
@@ -542,14 +583,14 @@ class UpdatePublishedArticlesReadDetail(object):
|
|
|
time.sleep(1)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
- bot(
|
|
|
- title="更新每日发布文章任务完成通知",
|
|
|
- detail={
|
|
|
- "msg": "服务号更新完成",
|
|
|
- "finish_time": datetime.today().__str__()
|
|
|
- },
|
|
|
- mention=False
|
|
|
- )
|
|
|
+ # bot(
|
|
|
+ # title="更新每日发布文章任务完成通知",
|
|
|
+ # detail={
|
|
|
+ # "msg": "服务号更新完成",
|
|
|
+ # "finish_time": datetime.today().__str__()
|
|
|
+ # },
|
|
|
+ # mention=False
|
|
|
+ # )
|
|
|
|
|
|
def check_job(self, biz_date: str = None):
|
|
|
"""
|
|
@@ -562,13 +603,13 @@ class UpdatePublishedArticlesReadDetail(object):
|
|
|
subscription_accounts = [i for i in account_list if i['account_type'] in const.SUBSCRIBE_TYPE_SET]
|
|
|
fail_list = []
|
|
|
# check and rework if fail
|
|
|
- for sub_item in tqdm(subscription_accounts):
|
|
|
+ for sub_item in tqdm(subscription_accounts[:10]):
|
|
|
res = self.check_single_account(sub_item)
|
|
|
if not res:
|
|
|
self.process_single_account(sub_item, biz_date)
|
|
|
|
|
|
# check whether success and bot if fails
|
|
|
- for sub_item in tqdm(subscription_accounts):
|
|
|
+ for sub_item in tqdm(subscription_accounts[:10]):
|
|
|
res = self.check_single_account(sub_item)
|
|
|
if not res:
|
|
|
# 去掉三个不需要查看的字段
|
|
@@ -578,14 +619,15 @@ class UpdatePublishedArticlesReadDetail(object):
|
|
|
fail_list.append(sub_item)
|
|
|
if fail_list:
|
|
|
try:
|
|
|
- bot(
|
|
|
- title="更新当天发布文章,存在未更新的账号",
|
|
|
- detail={
|
|
|
- "columns": generate_bot_columns(),
|
|
|
- "rows": fail_list
|
|
|
- },
|
|
|
- table=True
|
|
|
- )
|
|
|
+ print(fail_list)
|
|
|
+ # bot(
|
|
|
+ # title="更新当天发布文章,存在未更新的账号",
|
|
|
+ # detail={
|
|
|
+ # "columns": generate_bot_columns(),
|
|
|
+ # "rows": fail_list
|
|
|
+ # },
|
|
|
+ # table=True
|
|
|
+ # )
|
|
|
except Exception as e:
|
|
|
print("Timeout Error: {}".format(e))
|
|
|
else:
|