dy_ls.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import random
  2. import time
  3. import requests
  4. import json
  5. from common import Common, Feishu
  6. from common.sql_help import sqlCollect
  7. class DYLS:
  8. @classmethod
  9. def get_dyls_list(cls, task_mark, url_id, number, mark):
  10. next_cursor = ""
  11. for i in range(10):
  12. list = []
  13. try:
  14. # 抖查查
  15. url = "http://8.217.190.241:8888/crawler/dou_yin/blogger"
  16. payload = json.dumps({
  17. "account_id": url_id,
  18. "source": "抖查查",
  19. "cursor": next_cursor
  20. })
  21. headers = {
  22. 'Content-Type': 'application/json'
  23. }
  24. time.sleep(random.randint(1, 5))
  25. response = requests.request("POST", url, headers=headers, data=payload)
  26. response = response.json()
  27. data_all_list = response["data"]
  28. has_more = data_all_list["has_more"]
  29. next_cursor = str(data_all_list["next_cursor"])
  30. data_list = data_all_list["data"]
  31. for data in data_list:
  32. # comment_count = data["comment_count"]
  33. # download_count = data["download_count"]
  34. share_count = data["share_count"]
  35. good_count = data["good_count"]
  36. # collect_count = data["collect_count"]
  37. duration = data["duration"]
  38. video_id = data["video_id"]
  39. old_title = data["video_desc"]
  40. status = sqlCollect.is_used(video_id, mark, "抖音")
  41. if status:
  42. status = sqlCollect.is_used(video_id, mark, "抖音历史")
  43. if status == False:
  44. continue
  45. video_percent = '%.2f' % (int(share_count) / int(good_count))
  46. special = float(0.25)
  47. duration = duration / 1000
  48. if int(share_count) < 500 or float(video_percent) < special or int(duration) < 30 or int(duration) > 720:
  49. Common.logger("dy-ls").info(
  50. f"不符合规则:{task_mark},用户主页id:{url_id},视频id{video_id} ,分享:{share_count},点赞{good_count} ,时长:{int(duration)} ")
  51. continue
  52. video_url, image_url = cls.get_video(video_id)
  53. if video_url:
  54. all_data = {"video_id": video_id, "cover": image_url, "video_url": video_url, "rule": video_percent,
  55. "old_title": old_title}
  56. list.append(all_data)
  57. if len(list) == int(number):
  58. Common.logger("dy-ls").info(f"获取抖音历史视频总数:{len(list)}\n")
  59. return list
  60. else:
  61. Common.logger("dy-ls").info(f"抖音历史获取url失败")
  62. Feishu.finish_bot("dou_yin/detail接口无法获取到视频链接",
  63. "https://open.feishu.cn/open-apis/bot/v2/hook/575ca6a1-84b4-4a2f-983b-1d178e7b16eb",
  64. "【抖音异常提示 】")
  65. if has_more == False:
  66. return list
  67. except Exception as exc:
  68. Common.logger("dy-ls").info(f"抖音历史数据获取失败:{exc}\n")
  69. return list
  70. @classmethod
  71. def get_video(cls, video_id):
  72. url = "http://8.217.190.241:8888/crawler/dou_yin/detail"
  73. for i in range(3):
  74. payload = json.dumps({
  75. "content_id": str(video_id)
  76. })
  77. headers = {
  78. 'Content-Type': 'application/json'
  79. }
  80. response = requests.request("POST", url, headers=headers, data=payload)
  81. response = response.json()
  82. code = response["code"]
  83. if code == 10000:
  84. time.sleep(60)
  85. data = response["data"]["data"]
  86. video_url = data["video_url_list"][0]["video_url"]
  87. image_url = data["image_url_list"][0]["image_url"]
  88. return video_url, image_url
  89. return None, None
  90. if __name__ == '__main__':
  91. DYLS.get_video("7314923922602954022")
  92. # DYLS.get_dyls_list("1","MS4wLjABAAAA2QEvnEb7cQDAg6vZXq3j8_LlbO_DiturnV7VeybFKY4",1,"1")