blogger.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """
  2. @author: luojunhui
  3. """
  4. from __future__ import annotations
  5. import aiohttp
  6. from applications.utils import async_proxy
  7. from .use_js import call_js_function
  8. async def get_toutiao_account_info_list(
  9. account_id: str,
  10. cookie: str,
  11. media_type: str,
  12. max_behot_time=0,
  13. ) -> dict | None:
  14. """toutiao blogger"""
  15. ms_token = "mFs9gU4FJc23gFWPvBfQxFsBRrx1xBEJD_ZRTAolHfPrae84kTEBaHQR3s8ToiLX4-U9hgATTZ2cVHlSixmj5YCTOPoVM-43gOt3aVHkxfXHEuUtTJe-wUEs%3D"
  16. query_params = [
  17. 0,
  18. 1,
  19. 14,
  20. "category=pc_user_hot&token={}&aid=24&app_name=toutiao_web&msToken={}".format(
  21. account_id, ms_token
  22. ),
  23. "",
  24. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
  25. ]
  26. a_bogus = call_js_function(query_params)
  27. headers = {
  28. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
  29. "Cookie": cookie,
  30. "Content-Type": "application/json",
  31. }
  32. match media_type:
  33. case "article":
  34. url = f"https://www.toutiao.com/api/pc/list/user/feed?category=pc_profile_article&token={account_id}&max_behot_time={max_behot_time}&entrance_gid=&aid=24&app_name=toutiao_web&msToken={ms_token}&a_bogus={a_bogus}"
  35. case "video":
  36. url = f"https://www.toutiao.com/api/pc/list/user/feed?category=pc_profile_video&token={account_id}&max_behot_time={max_behot_time}&hot_video=0&entrance_gid=&aid=24&app_name=toutiao_web&msToken={ms_token}&a_bogus={a_bogus}"
  37. case _:
  38. return None
  39. proxy_url = async_proxy()["url"]
  40. proxy_auth = aiohttp.BasicAuth(async_proxy()["username"], async_proxy()["password"])
  41. async with aiohttp.ClientSession() as session:
  42. async with session.get(
  43. url, headers=headers, proxy=proxy_url, proxy_auth=proxy_auth
  44. ) as response:
  45. response.raise_for_status()
  46. return await response.json()