|
@@ -44,7 +44,7 @@ class CrawlerAccountManager(CrawlerAccountManagerConst):
|
|
|
raise RuntimeError(f"Unknown platform: {platform}")
|
|
|
|
|
|
account_list = await self.pool.async_fetch(query)
|
|
|
- return [i['account_id'] for i in account_list]
|
|
|
+ return [i["account_id"] for i in account_list]
|
|
|
|
|
|
|
|
|
class WeixinAccountManager(CrawlerAccountManager):
|
|
@@ -77,7 +77,9 @@ class WeixinAccountManager(CrawlerAccountManager):
|
|
|
],
|
|
|
)
|
|
|
|
|
|
- async def update_account_stat_detail(self, account_id: str, history_info: Dict, recently_info: Dict) -> int:
|
|
|
+ async def update_account_stat_detail(
|
|
|
+ self, account_id: str, history_info: Dict, recently_info: Dict
|
|
|
+ ) -> int:
|
|
|
"""更新账号统计详情"""
|
|
|
query = f"""
|
|
|
update long_articles_accounts
|
|
@@ -86,14 +88,15 @@ class WeixinAccountManager(CrawlerAccountManager):
|
|
|
where gh_id = %s;
|
|
|
"""
|
|
|
return await self.pool.async_save(
|
|
|
- query=query, params=(
|
|
|
+ query=query,
|
|
|
+ params=(
|
|
|
history_info["publish_frequency"],
|
|
|
history_info["ci_lower"],
|
|
|
recently_info["publish_frequency"],
|
|
|
recently_info["ci_lower"],
|
|
|
account_id,
|
|
|
datetime.today().strftime("%Y-%m-%d"),
|
|
|
- )
|
|
|
+ ),
|
|
|
)
|
|
|
|
|
|
def analysis_dataframe(self, dataframe: DataFrame) -> Optional[Dict]:
|
|
@@ -113,26 +116,27 @@ class WeixinAccountManager(CrawlerAccountManager):
|
|
|
publish_times = dataframe["publish_time"].dropna()
|
|
|
if len(publish_times) >= 2:
|
|
|
delta = publish_times.max() - publish_times.min()
|
|
|
- publish_frequency = (len(publish_times) / delta
|
|
|
- * self.ONE_DAY_TIMESTAMP) if delta else 0.0
|
|
|
+ publish_frequency = (
|
|
|
+ (len(publish_times) / delta * self.ONE_DAY_TIMESTAMP) if delta else 0.0
|
|
|
+ )
|
|
|
else:
|
|
|
publish_frequency = 0.0
|
|
|
|
|
|
return {
|
|
|
- "publish_frequency": self.safe_float(publish_frequency),
|
|
|
- "ci_lower": self.safe_float(ci_lower),
|
|
|
- "ci_upper": self.safe_float(ci_upper),
|
|
|
- }
|
|
|
+ "publish_frequency": self.safe_float(publish_frequency),
|
|
|
+ "ci_lower": self.safe_float(ci_lower),
|
|
|
+ "ci_upper": self.safe_float(ci_upper),
|
|
|
+ }
|
|
|
|
|
|
async def analysis_single_account(self, account_id: str) -> None:
|
|
|
dataframe = await self.get_account_crawler_articles_info(account_id)
|
|
|
history_articles_analysis = self.analysis_dataframe(dataframe)
|
|
|
thirty_days_before = int(time.time()) - self.THIRTY_DAYS_TIMESTAMP
|
|
|
- recent_30_days_df = dataframe[
|
|
|
- dataframe["publish_time"] >= thirty_days_before
|
|
|
- ]
|
|
|
+ recent_30_days_df = dataframe[dataframe["publish_time"] >= thirty_days_before]
|
|
|
recent_30_days_analysis = self.analysis_dataframe(recent_30_days_df)
|
|
|
- await self.update_account_stat_detail(account_id, history_articles_analysis, recent_30_days_analysis)
|
|
|
+ await self.update_account_stat_detail(
|
|
|
+ account_id, history_articles_analysis, recent_30_days_analysis
|
|
|
+ )
|
|
|
|
|
|
async def deal(self, platform, account_id_list: Optional[List[str]] = None) -> None:
|
|
|
"""deal"""
|
|
@@ -141,7 +145,3 @@ class WeixinAccountManager(CrawlerAccountManager):
|
|
|
|
|
|
for account_id in account_id_list:
|
|
|
await self.analysis_single_account(account_id)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|