ks_xcx.py 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import json
  2. import requests
  3. from utils.aliyun_log import AliyunLogger
  4. from utils.feishu_form import Material
  5. from utils.sql_help import sqlCollect
  6. class KSXCX:
  7. @classmethod
  8. def get_xcx_date(cls, task, fs_channel_name):
  9. list = []
  10. try:
  11. url = "http://8.217.192.46:8889/crawler/kuai_shou/mp_recommend"
  12. payload = json.dumps({
  13. "cursor": ""
  14. })
  15. headers = {
  16. 'Content-Type': 'application/json'
  17. }
  18. response = requests.request("POST", url, headers=headers, data=payload)
  19. response = response.json()
  20. code = response['code']
  21. if code == 0:
  22. data_list = response['data']['data']
  23. for data in data_list:
  24. type = int(data['type'])
  25. if type != 1:
  26. continue
  27. photo_type = data['photoType']
  28. if photo_type != "VIDEO":
  29. continue
  30. duration = int(int(data["duration"])/1000)
  31. cover_url = data['webpCoverUrls'][0]['url']
  32. video_url = data['mainMvUrls'][0]['url']
  33. like_count = data.get('likeCount', 0)
  34. share_count = data.get('shareCount', 0)
  35. view_count = data.get('viewCount', 0)
  36. title = data['caption']
  37. photo_id = data['photoId']
  38. user_name = data['share_info']
  39. log_data = f"user:快手小程序,,video_id:{photo_id},,video_url:{video_url},original_title:{title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}"
  40. AliyunLogger.logging("快手小程序", "快手小程序",user_name, photo_id, "扫描到一条视频", "2001", log_data)
  41. day_count = Material.get_count_restrict(task["channel"])
  42. if day_count:
  43. status = sqlCollect.is_used_days(photo_id, task['channel'], day_count)
  44. else:
  45. status = sqlCollect.is_used(photo_id, task['channel'])
  46. if status:
  47. AliyunLogger.logging("快手小程序", "快手小程序", user_name,photo_id, "该视频已改造过", "2002", log_data)
  48. continue
  49. if duration <= 30:
  50. AliyunLogger.logging("快手小程序", "快手小程序",user_name, photo_id,
  51. f"不符合规则:时长不符合规则小于30秒,视频时长{duration}", "2003",
  52. log_data)
  53. continue
  54. if int(share_count) < 1000:
  55. AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id,
  56. f"分享小于1000,实际点赞{share_count}", "2003",
  57. log_data)
  58. continue
  59. video_percent = '%.4f' % (int(share_count) / int(like_count))
  60. if float(video_percent) < 0.15:
  61. AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id,
  62. f"分享/点赞 < 15%,实际占比{video_percent}", "2003",
  63. log_data)
  64. continue
  65. all_data = {"video_id": photo_id, "cover": cover_url, "video_url": video_url,
  66. "rule": video_percent,
  67. "old_title": title}
  68. if not list and any(item["video_id"] == all_data["video_id"] for item in list):
  69. AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id, "重复视频", "2002",
  70. log_data)
  71. continue
  72. list.append(all_data)
  73. AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id, "符合规则等待改造", "2004", log_data)
  74. return list
  75. except Exception as e:
  76. return list
  77. if __name__ == '__main__':
  78. KSXCX.get_xcx_date()