account_crawler_task.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # get videos with score to sync to feishu
  63. video_list = crawler.get_video_list_with_score(platform=platform)
  64. if video_list:
  65. insert_data_into_feishu_sheet(platform=platform, data_list=video_list)
  66. video_id_list= [i[0] for i in video_list]
  67. # update status
  68. crawler.update_video_status(
  69. video_id_tuple=tuple(video_id_list), ori_status=0, new_status=1
  70. )
  71. if __name__ == "__main__":
  72. platform_list = ["sph", "hksp", "toutiao"]
  73. for platform in platform_list:
  74. deal_each_platform(platform=platform)