account_crawler_task.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """
  2. @author: luojunhui
  3. @description: try to get some more accounts
  4. """
  5. import datetime
  6. from applications.api.feishu_api import FeishuSheetApi
  7. from tasks.crawler_accounts_by_association import ChannelsAccountCrawler
  8. from tasks.crawler_accounts_by_association import ToutiaoAccountCrawler
  9. from tasks.crawler_accounts_by_association import HaoKanAccountCrawler
  10. document_token = "BGQCsOXwHhVRq5tswjgcI8NInqd"
  11. toutiao_sheet_id = "pIJSt7"
  12. channels_sheet_id = "ee0163"
  13. haokan_sheet_id = "tfftfD"
  14. def insert_data_into_feishu_sheet(platform: str, data_list: list[list[str]]) -> None:
  15. """
  16. insert data info into feishu sheet
  17. :param platform: str, channels or toutiao
  18. :param data_list: list[list[str]],
  19. """
  20. video_array = [
  21. list(i) + [datetime.date.today().strftime("%Y-%m-%d")] for i in data_list
  22. ]
  23. feishu_sheet = FeishuSheetApi()
  24. feishu_sheet.fetch_token()
  25. match platform:
  26. case "toutiao":
  27. sheet_id = toutiao_sheet_id
  28. case "sph":
  29. sheet_id = channels_sheet_id
  30. case "hksp":
  31. sheet_id = haokan_sheet_id
  32. case _:
  33. raise RuntimeError("platform error")
  34. feishu_sheet.prepend_value(
  35. sheet_token=document_token,
  36. sheet_id=sheet_id,
  37. values=[["******"]],
  38. ranges="A2:A2",
  39. )
  40. feishu_sheet.insert_value(
  41. sheet_token=document_token,
  42. sheet_id=sheet_id,
  43. values=video_array,
  44. ranges="A2:J{}".format(2 + len(video_array)),
  45. )
  46. def deal_each_platform(platform: str) -> None:
  47. """
  48. deal each platform
  49. :param platform: str, channels or toutiao
  50. """
  51. match platform:
  52. case "toutiao":
  53. crawler = ToutiaoAccountCrawler()
  54. case "sph":
  55. crawler = ChannelsAccountCrawler()
  56. case "hksp":
  57. crawler = HaoKanAccountCrawler()
  58. case _:
  59. raise RuntimeError("platform error")
  60. # start process
  61. crawler.deal()
  62. if __name__ == "__main__":
  63. platform_list = ["toutiao", "sph", "hksp"]
  64. for platform_id in platform_list:
  65. deal_each_platform(platform=platform_id)