|
@@ -374,19 +374,18 @@ class FwhGroupPublishMonitor(FwhDataRecycle):
|
|
|
get the number of fans sent on the specified date
|
|
|
"""
|
|
|
fetch_query = f"""
|
|
|
- select sum(sent_count) as 'total_sent_fans'
|
|
|
+ select push_id, avg(sent_count) as 'total_sent_fans'
|
|
|
from long_articles_group_send_result
|
|
|
- where publish_date = %s
|
|
|
- and gh_id = %s
|
|
|
- and status = %s;
|
|
|
+ where publish_date = %s and gh_id = %s and status = %s
|
|
|
+ group by push_id;
|
|
|
"""
|
|
|
fetch_response = self.long_articles_client.fetch(
|
|
|
fetch_query,
|
|
|
cursor_type=DictCursor,
|
|
|
params=(date_string, gh_id, self.PUBLISH_SUCCESS_STATUS),
|
|
|
)
|
|
|
- fans_count = fetch_response[0]["total_sent_fans"]
|
|
|
- return fans_count if fans_count else 0
|
|
|
+ fans_list = [i["total_sent_fans"] for i in fetch_response]
|
|
|
+ return sum(fans_list) if fans_list else 0
|
|
|
|
|
|
def get_remain_fans(self, gh_id: str):
|
|
|
"""
|
|
@@ -418,18 +417,32 @@ class FwhGroupPublishMonitor(FwhDataRecycle):
|
|
|
response = fetch_response[0]["remain_publish_times"]
|
|
|
return response if response else 0
|
|
|
|
|
|
+ def get_remain_fans_and_publish_times(self, gh_id: str, date_string: str):
|
|
|
+ """
|
|
|
+ 获取发布前,该账号剩余的发布次数和粉丝数
|
|
|
+ """
|
|
|
+ fetch_query = f"""
|
|
|
+ select fans_before_publish, publish_times_before_publish
|
|
|
+ from fwh_daily_publish_detail
|
|
|
+ where gh_id = %s and publish_date = %s;
|
|
|
+ """
|
|
|
+ fetch_response = self.piaoquan_client.fetch(
|
|
|
+ fetch_query, cursor_type=DictCursor, params=(gh_id, date_string)
|
|
|
+ )
|
|
|
+ return fetch_response[0] if fetch_response else None
|
|
|
+
|
|
|
def deal(self, date_string: str = datetime.today().strftime("%Y-%m-%d")):
|
|
|
"""
|
|
|
monitor the publish record
|
|
|
"""
|
|
|
now = datetime.now()
|
|
|
- # if now.hour < 12:
|
|
|
+ if now.hour > 12:
|
|
|
+ return
|
|
|
+
|
|
|
gh_id_list = self.get_group_server_accounts()
|
|
|
|
|
|
# get rest publish days
|
|
|
remain_days = days_remaining_in_month()
|
|
|
- print(remain_days)
|
|
|
- print(type(remain_days))
|
|
|
|
|
|
# get table columns
|
|
|
columns = [
|
|
@@ -463,15 +476,16 @@ class FwhGroupPublishMonitor(FwhDataRecycle):
|
|
|
for gh_id in gh_id_list:
|
|
|
account_name = self.get_server_account_name(gh_id)
|
|
|
# 获取今日发布粉丝数量
|
|
|
- print(account_name, "\t", gh_id)
|
|
|
sent_fans = self.get_sent_fans(date_string, gh_id)
|
|
|
- print(sent_fans)
|
|
|
-
|
|
|
- # 获取剩余可发文人数
|
|
|
- remain_fans = self.get_remain_fans(gh_id)
|
|
|
-
|
|
|
- # 获取剩余可发文次数
|
|
|
- remain_publish_times = self.get_remain_publish_times(gh_id)
|
|
|
+ # # 获取剩余可发文人数
|
|
|
+ # remain_fans = self.get_remain_fans(gh_id)
|
|
|
+ #
|
|
|
+ # # 获取剩余可发文次数
|
|
|
+ # remain_publish_times = self.get_remain_publish_times(gh_id)
|
|
|
+
|
|
|
+ remain_fans, remain_publish_times = self.get_remain_fans_and_publish_times(
|
|
|
+ gh_id, date_string
|
|
|
+ )
|
|
|
temp = {
|
|
|
"account_name": account_name,
|
|
|
"rest_publish_times": int(remain_publish_times + sent_fans),
|
|
@@ -490,4 +504,4 @@ class FwhGroupPublishMonitor(FwhDataRecycle):
|
|
|
table=True,
|
|
|
mention=False,
|
|
|
env="server_account_publish_monitor",
|
|
|
- )
|
|
|
+ )
|