|
@@ -211,9 +211,7 @@ class AutoReplyCardsMonitorMapper(AutoReplyCardsMonitorUtils):
|
|
|
FROM cooperate_accounts
|
|
FROM cooperate_accounts
|
|
|
WHERE account_name = %s;
|
|
WHERE account_name = %s;
|
|
|
"""
|
|
"""
|
|
|
- return await self.pool.async_fetch(
|
|
|
|
|
- query=query, params=(account_name,)
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return await self.pool.async_fetch(query=query, params=(account_name,))
|
|
|
|
|
|
|
|
# 更新账号状态为无效
|
|
# 更新账号状态为无效
|
|
|
async def set_account_as_invalid(self, gh_id):
|
|
async def set_account_as_invalid(self, gh_id):
|
|
@@ -228,7 +226,11 @@ class AutoReplyCardsMonitorMapper(AutoReplyCardsMonitorUtils):
|
|
|
query = """
|
|
query = """
|
|
|
INSERT INTO gzh_msg_record (task_id, biz_type, task_params, create_timestamp, update_timestamp) VALUES (%s, %s, %s, %s, %s);
|
|
INSERT INTO gzh_msg_record (task_id, biz_type, task_params, create_timestamp, update_timestamp) VALUES (%s, %s, %s, %s, %s);
|
|
|
"""
|
|
"""
|
|
|
- return await self.pool.async_save(query=query, params=(task_id, "follow", link, timestamp, timestamp), db_name="aigc")
|
|
|
|
|
|
|
+ return await self.pool.async_save(
|
|
|
|
|
+ query=query,
|
|
|
|
|
+ params=(task_id, "follow", link, timestamp, timestamp),
|
|
|
|
|
+ db_name="aigc",
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 插入AIGC自动回复任务
|
|
# 插入AIGC自动回复任务
|
|
|
async def insert_aigc_auto_reply_task(self, task_id, account_name):
|
|
async def insert_aigc_auto_reply_task(self, task_id, account_name):
|
|
@@ -236,7 +238,11 @@ class AutoReplyCardsMonitorMapper(AutoReplyCardsMonitorUtils):
|
|
|
query = """
|
|
query = """
|
|
|
INSERT INTO gzh_msg_record (task_id, task_params, create_timestamp, update_timestamp) VALUES (%s, %s, %s, %s);
|
|
INSERT INTO gzh_msg_record (task_id, task_params, create_timestamp, update_timestamp) VALUES (%s, %s, %s, %s);
|
|
|
"""
|
|
"""
|
|
|
- return await self.pool.async_save(query=query, params=(task_id, account_name, timestamp, timestamp), db_name="aigc")
|
|
|
|
|
|
|
+ return await self.pool.async_save(
|
|
|
|
|
+ query=query,
|
|
|
|
|
+ params=(task_id, account_name, timestamp, timestamp),
|
|
|
|
|
+ db_name="aigc",
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 为账号设置 sample_url
|
|
# 为账号设置 sample_url
|
|
|
async def set_sample_url(self, gh_id, sample_url):
|
|
async def set_sample_url(self, gh_id, sample_url):
|
|
@@ -250,7 +256,9 @@ class AutoReplyCardsMonitorMapper(AutoReplyCardsMonitorUtils):
|
|
|
query = """
|
|
query = """
|
|
|
UPDATE cooperate_accounts SET follow_status = %s WHERE gh_id = %s and follow_status = %s;
|
|
UPDATE cooperate_accounts SET follow_status = %s WHERE gh_id = %s and follow_status = %s;
|
|
|
"""
|
|
"""
|
|
|
- return await self.pool.async_save(query=query, params=(new_status, gh_id, ori_status))
|
|
|
|
|
|
|
+ return await self.pool.async_save(
|
|
|
|
|
+ query=query, params=(new_status, gh_id, ori_status)
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 从 aigc 获取关注结果
|
|
# 从 aigc 获取关注结果
|
|
|
async def fetch_follow_account_status(self, gh_id):
|
|
async def fetch_follow_account_status(self, gh_id):
|
|
@@ -274,17 +282,21 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorMapper):
|
|
|
code = response.get("code")
|
|
code = response.get("code")
|
|
|
match code:
|
|
match code:
|
|
|
case 0:
|
|
case 0:
|
|
|
- recent_articles = response['data']['data'][0]['AppMsg']['DetailInfo']
|
|
|
|
|
|
|
+ recent_articles = response["data"]["data"][0]["AppMsg"]["DetailInfo"]
|
|
|
article_url = await self.get_sample_url(recent_articles)
|
|
article_url = await self.get_sample_url(recent_articles)
|
|
|
print(article_url)
|
|
print(article_url)
|
|
|
if article_url:
|
|
if article_url:
|
|
|
await self.set_sample_url(gh_id, article_url)
|
|
await self.set_sample_url(gh_id, article_url)
|
|
|
|
|
|
|
|
task_id = self.generate_task_id(task_name="follow", gh_id=gh_id)
|
|
task_id = self.generate_task_id(task_name="follow", gh_id=gh_id)
|
|
|
- affected_rows = await self.insert_aigc_follow_account_task(task_id, article_url)
|
|
|
|
|
|
|
+ affected_rows = await self.insert_aigc_follow_account_task(
|
|
|
|
|
+ task_id, article_url
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
if affected_rows:
|
|
if affected_rows:
|
|
|
- await self.update_follow_status(gh_id, self.INIT_STATUS, self.PROCESSING_STATUS)
|
|
|
|
|
|
|
+ await self.update_follow_status(
|
|
|
|
|
+ gh_id, self.INIT_STATUS, self.PROCESSING_STATUS
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
case 25013:
|
|
case 25013:
|
|
|
await self.set_account_as_invalid(gh_id)
|
|
await self.set_account_as_invalid(gh_id)
|
|
@@ -314,12 +326,20 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorMapper):
|
|
|
|
|
|
|
|
match follow_status:
|
|
match follow_status:
|
|
|
case self.INIT_STATUS:
|
|
case self.INIT_STATUS:
|
|
|
- await self.create_follow_account_task(account_detail["gh_id"])
|
|
|
|
|
|
|
+ await self.create_follow_account_task(
|
|
|
|
|
+ account_detail["gh_id"]
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
case self.PROCESSING_STATUS:
|
|
case self.PROCESSING_STATUS:
|
|
|
- fetch_response = await self.fetch_follow_account_status(account_detail["gh_id"])
|
|
|
|
|
|
|
+ fetch_response = await self.fetch_follow_account_status(
|
|
|
|
|
+ account_detail["gh_id"]
|
|
|
|
|
+ )
|
|
|
if not fetch_response:
|
|
if not fetch_response:
|
|
|
- await self.update_follow_status(account_detail["gh_id"], self.PROCESSING_STATUS, self.INIT_STATUS)
|
|
|
|
|
|
|
+ await self.update_follow_status(
|
|
|
|
|
+ account_detail["gh_id"],
|
|
|
|
|
+ self.PROCESSING_STATUS,
|
|
|
|
|
+ self.INIT_STATUS,
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
task_status = fetch_response[0]["task_status"]
|
|
task_status = fetch_response[0]["task_status"]
|
|
|
match task_status:
|
|
match task_status:
|
|
@@ -328,9 +348,17 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorMapper):
|
|
|
case self.FETCH_PROCESSING_STATUS:
|
|
case self.FETCH_PROCESSING_STATUS:
|
|
|
continue
|
|
continue
|
|
|
case self.FETCH_SUCCESS_STATUS:
|
|
case self.FETCH_SUCCESS_STATUS:
|
|
|
- await self.update_follow_status(account_detail["gh_id"], self.PROCESSING_STATUS, self.SUCCESS_STATUS)
|
|
|
|
|
|
|
+ await self.update_follow_status(
|
|
|
|
|
+ account_detail["gh_id"],
|
|
|
|
|
+ self.PROCESSING_STATUS,
|
|
|
|
|
+ self.SUCCESS_STATUS,
|
|
|
|
|
+ )
|
|
|
case self.FETCH_FAIL_STATUS:
|
|
case self.FETCH_FAIL_STATUS:
|
|
|
- await self.update_follow_status(account_detail["gh_id"], self.PROCESSING_STATUS, self.FAIL_STATUS)
|
|
|
|
|
|
|
+ await self.update_follow_status(
|
|
|
|
|
+ account_detail["gh_id"],
|
|
|
|
|
+ self.PROCESSING_STATUS,
|
|
|
|
|
+ self.FAIL_STATUS,
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
case self.SUCCESS_STATUS:
|
|
case self.SUCCESS_STATUS:
|
|
|
continue
|
|
continue
|
|
@@ -341,7 +369,6 @@ class AutoReplyCardsMonitor(AutoReplyCardsMonitorMapper):
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
print(f"处理账号{account.公众号名}异常", e)
|
|
print(f"处理账号{account.公众号名}异常", e)
|
|
|
|
|
|
|
|
-
|
|
|
|
|
# main function
|
|
# main function
|
|
|
async def deal(self, task_name):
|
|
async def deal(self, task_name):
|
|
|
match task_name:
|
|
match task_name:
|