ks_xcx.py 4.1 KB

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