ks_xcx.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import json
  2. import time
  3. import requests
  4. from common import Feishu, AliyunLogger
  5. from common.sql_help import sqlCollect
  6. class KSXCX:
  7. @classmethod
  8. def get_xcx_date(cls):
  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. timestamp = data['timestamp']
  35. share_count = data.get('shareCount', 0)
  36. comment_count = data.get('commentCount', 0)
  37. view_count = data.get('viewCount', 0)
  38. title = data['caption']
  39. photo_id = data['photoId']
  40. user_name = data['userName']
  41. 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}"
  42. AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "扫描到一条视频", "2001", log_data)
  43. status = sqlCollect.ks_is_used_xcx(photo_id,"快手小程序")
  44. if status:
  45. AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "该视频已改造过", "2002", log_data)
  46. continue
  47. if duration <= 30:
  48. AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id,
  49. f"不符合规则:时长不符合规则小于30秒,视频时长{duration}", "2003",
  50. log_data)
  51. continue
  52. if int(share_count) < 1000:
  53. AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id,
  54. f"分享小于1000,实际点赞{share_count}", "2003",
  55. log_data)
  56. continue
  57. video_percent = '%.4f' % (int(share_count) / int(like_count))
  58. if float(video_percent) < 0.15:
  59. AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id,
  60. f"分享/点赞 < 15%,实际占比{video_percent}", "2003",
  61. log_data)
  62. continue
  63. all_data = {"video_id": photo_id, "cover": cover_url, "video_url": video_url,
  64. "rule": video_percent,
  65. "old_title": title}
  66. if not list and any(item["video_id"] == all_data["video_id"] for item in list):
  67. AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "重复视频", "2002",
  68. log_data)
  69. continue
  70. list.append(all_data)
  71. AliyunLogger.logging("快手小程序", user_name, "快手小程序", photo_id, "符合规则等待改造", "2004", log_data)
  72. return list
  73. except Exception as e:
  74. return list
  75. if __name__ == '__main__':
  76. KSXCX.get_xcx_date()