|
@@ -1,5 +1,6 @@
|
|
|
import json
|
|
import json
|
|
|
import time
|
|
import time
|
|
|
|
|
+import traceback
|
|
|
from datetime import datetime, timedelta
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
from applications.api import feishu_robot
|
|
from applications.api import feishu_robot
|
|
@@ -33,9 +34,9 @@ class ArticleDetailStatConst:
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleDetailStatMapper(ArticleDetailStatConst):
|
|
class ArticleDetailStatMapper(ArticleDetailStatConst):
|
|
|
- def __init__(self, pool, log_client):
|
|
|
|
|
|
|
+ def __init__(self, pool, log_service):
|
|
|
self.pool = pool
|
|
self.pool = pool
|
|
|
- self.log_client = log_client
|
|
|
|
|
|
|
+ self.log_service = log_service
|
|
|
|
|
|
|
|
# 获取账号信息
|
|
# 获取账号信息
|
|
|
async def fetch_monitor_accounts(self):
|
|
async def fetch_monitor_accounts(self):
|
|
@@ -135,8 +136,8 @@ class ArticleDetailStatMapper(ArticleDetailStatConst):
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArticleDetailStat(ArticleDetailStatMapper):
|
|
class ArticleDetailStat(ArticleDetailStatMapper):
|
|
|
- def __init__(self, pool, log_client):
|
|
|
|
|
- super().__init__(pool, log_client)
|
|
|
|
|
|
|
+ def __init__(self, pool, log_service):
|
|
|
|
|
+ super().__init__(pool, log_service)
|
|
|
|
|
|
|
|
# 存储账号信息
|
|
# 存储账号信息
|
|
|
async def save_account_details(self, account, fetch_response):
|
|
async def save_account_details(self, account, fetch_response):
|
|
@@ -282,7 +283,7 @@ class ArticleDetailStat(ArticleDetailStatMapper):
|
|
|
# yesterday_string = datetime.strftime(datetime.now() - timedelta(days=5), "%Y-%m-%d")
|
|
# yesterday_string = datetime.strftime(datetime.now() - timedelta(days=5), "%Y-%m-%d")
|
|
|
dt_list = [
|
|
dt_list = [
|
|
|
(datetime.now() - timedelta(days=i)).strftime("%Y-%m-%d")
|
|
(datetime.now() - timedelta(days=i)).strftime("%Y-%m-%d")
|
|
|
- for i in range(1, 31)
|
|
|
|
|
|
|
+ for i in range(1, 2)
|
|
|
]
|
|
]
|
|
|
for dt in dt_list:
|
|
for dt in dt_list:
|
|
|
print(f"{account['account_name']} crawl {dt} read_data")
|
|
print(f"{account['account_name']} crawl {dt} read_data")
|
|
@@ -304,5 +305,26 @@ class ArticleDetailStat(ArticleDetailStatMapper):
|
|
|
# 入口函数
|
|
# 入口函数
|
|
|
async def deal(self):
|
|
async def deal(self):
|
|
|
accounts = await self.fetch_monitor_accounts()
|
|
accounts = await self.fetch_monitor_accounts()
|
|
|
|
|
+ if not accounts:
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
for account in accounts:
|
|
for account in accounts:
|
|
|
- await self.process_single_account(account)
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ await self.process_single_account(account)
|
|
|
|
|
+ await self.log_service.log(
|
|
|
|
|
+ contents={
|
|
|
|
|
+ "task": "article_detail_stat",
|
|
|
|
|
+ "account_name": account["account_name"],
|
|
|
|
|
+ "status": "success"
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ await self.log_service.log(
|
|
|
|
|
+ contents={
|
|
|
|
|
+ "task": "article_detail_stat",
|
|
|
|
|
+ "account_name": account["account_name"],
|
|
|
|
|
+ "error": str(e),
|
|
|
|
|
+ "traceback": traceback.format_exc(),
|
|
|
|
|
+ "status": "fail"
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|