|
|
@@ -5,6 +5,7 @@ from applications.crawler.wechat import (
|
|
|
get_access_token,
|
|
|
get_union_id_batch,
|
|
|
)
|
|
|
+from applications.api import feishu_robot
|
|
|
from applications.utils import run_tasks_with_asyncio_task_group
|
|
|
|
|
|
|
|
|
@@ -109,6 +110,9 @@ class CrawlerGzhFans(CrawlerGzhFansBase):
|
|
|
# 抓取单个账号的粉丝
|
|
|
async def crawl_fans_for_each_account(self, account_info):
|
|
|
cookie_obj = await self.get_cookie_token_from_database(account_info["gh_id"])
|
|
|
+ if not cookie_obj:
|
|
|
+ return
|
|
|
+
|
|
|
if not account_info.get("cursor_openid"):
|
|
|
cursor_openid = ''
|
|
|
else:
|
|
|
@@ -126,7 +130,6 @@ class CrawlerGzhFans(CrawlerGzhFansBase):
|
|
|
cursor_timestamp=cursor_timestamp,
|
|
|
)
|
|
|
base_resp = response.get("base_resp", {})
|
|
|
- # print(json.dumps(base_resp, indent=4, ensure_ascii=False))
|
|
|
code = base_resp.get("ret")
|
|
|
error_msg = base_resp.get("err_msg")
|
|
|
|
|
|
@@ -135,14 +138,30 @@ class CrawlerGzhFans(CrawlerGzhFansBase):
|
|
|
user_list = response.get("user_list", {}).get("user_info_list")
|
|
|
next_cursor_id = user_list[-1].get("user_openid")
|
|
|
next_cursor_timestamp = user_list[-1].get("user_create_time")
|
|
|
- # print(json.dumps(user_list, ensure_ascii=False, indent=4))
|
|
|
await self.insert_gzh_fans_batch(account_info, user_list)
|
|
|
await self.update_gzh_cursor_info(
|
|
|
account_info["gh_id"], next_cursor_id, next_cursor_timestamp
|
|
|
)
|
|
|
|
|
|
+ case '00040':
|
|
|
+ print(f"token 非法: {error_msg}")
|
|
|
+ await self.set_cookie_token_as_invalid(account_info["gh_id"])
|
|
|
+ await feishu_robot.bot(
|
|
|
+ title=f"{account_info['account_name']}的 token && cookie 失效,请及时更新",
|
|
|
+ detail=account_info,
|
|
|
+ env="cookie_monitor_bot",
|
|
|
+ mention=False,
|
|
|
+ )
|
|
|
+
|
|
|
case _:
|
|
|
- print(code, error_msg)
|
|
|
+ print("token 异常, 请及时刷新")
|
|
|
+ await self.set_cookie_token_as_invalid(account_info["gh_id"])
|
|
|
+ await feishu_robot.bot(
|
|
|
+ title=f"{account_info['account_name']}的 token && cookie 失效,请及时更新",
|
|
|
+ detail=account_info,
|
|
|
+ env="cookie_monitor_bot",
|
|
|
+ mention=False,
|
|
|
+ )
|
|
|
|
|
|
# 通过 access_token && open_id 抓取 union_id
|
|
|
async def get_union_ids_for_each_account(self, account_info: dict):
|