sph.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # import json
  2. # import random
  3. # import time
  4. #
  5. # import requests
  6. #
  7. #
  8. """需兼容"""
  9. # class SPH:
  10. #
  11. # @classmethod
  12. # def find_target_user(cls, name, user_list):
  13. # """
  14. # 在搜索到到账号列表中找目标列表
  15. # """
  16. # for obj in user_list:
  17. # if obj['contact']["nickname"] == name:
  18. # return obj
  19. # else:
  20. # continue
  21. # return False
  22. #
  23. # @classmethod
  24. # def get_account_id(cls, account_name):
  25. # channel = 'shipinhao'
  26. # history_id = sqlCollect.get_history_id(channel, account_name)
  27. # if history_id:
  28. # return history_id
  29. # else:
  30. # url = "http://8.217.192.46:8889/crawler/wei_xin/shi_pin_hao/account_info"
  31. # payload = json.dumps({
  32. # "account_name": account_name
  33. # })
  34. # headers = {
  35. # 'Content-Type': 'application/json'
  36. # }
  37. #
  38. # response = requests.request("POST", url, headers=headers, data=payload)
  39. # response = response.json()
  40. # if response['code'] == 0:
  41. # data = response['data']['data']
  42. #
  43. # channel_account_id = data['channel_account_id']
  44. # if channel_account_id:
  45. # sqlCollect.insert_history_id(account_name, channel_account_id, channel)
  46. #
  47. #
  48. # return channel_account_id
  49. # else:
  50. # return False
  51. # else:
  52. # Feishu.finish_bot("shi_pin_hao/account_info接口获取失败",
  53. # "https://open.feishu.cn/open-apis/bot/v2/hook/575ca6a1-84b4-4a2f-983b-1d178e7b16eb",
  54. # "【视频号接口异常提示 】")
  55. # return False
  56. #
  57. # @classmethod
  58. # def get_sph_url(cls, task_mark, url_id, number, mark, channel_id, name):
  59. # account_id = cls.get_account_id(url_id)
  60. # if account_id:
  61. # url = "http://8.217.192.46:8889/crawler/wei_xin/shi_pin_hao/blogger"
  62. # next_cursor = ""
  63. # list = []
  64. # # for i in range(10):
  65. # headers = {
  66. # 'Content-Type': 'application/json'
  67. # }
  68. # payload = json.dumps({
  69. # "account_id": account_id,
  70. # "cursor": next_cursor
  71. # })
  72. # try:
  73. # response = requests.request("POST", url, headers=headers, data=payload, timeout=30)
  74. # time.sleep(random.randint(1, 5))
  75. # res_json = response.json()
  76. # if res_json['code'] == 0:
  77. # # next_cursor = res_json['data']['next_cursor']
  78. # data_lsit = res_json['data']['data']
  79. # if data_lsit == None:
  80. # return list
  81. # for obj in data_lsit:
  82. # objectId = obj['id']
  83. # day_count = Material.get_count_restrict(channel_id)
  84. # if day_count:
  85. # status = sqlCollect.is_used_days(objectId, mark, "视频号", day_count)
  86. # else:
  87. # status = sqlCollect.is_used( objectId, mark, "视频号")
  88. #
  89. # old_title = obj['objectDesc']['description']
  90. # url_p = obj['objectDesc']['media'][0]['Url']
  91. # url_token = obj['objectDesc']['media'][0]['urlToken']
  92. # video_url = f"{url_p}{url_token}"
  93. # decode_key = obj['objectDesc']['media'][0]['decodeKey']
  94. # cover = obj['objectDesc']['media'][0]['coverUrl']
  95. #
  96. # share_cnt = int(obj['forwardCount']) # 分享
  97. # like_cnt = int(obj['likeCount']) # 点赞
  98. # duration = int(obj['objectDesc']['media'][0]['VideoPlayLen'])
  99. # # duration = int(duration_ms) / 1000
  100. #
  101. # log_data = f"user:{url_id},,video_id:{objectId},,video_url:{video_url},,original_title:{old_title},,share_count:{share_cnt},,like_count:{like_cnt},,duration:{duration}"
  102. # AliyunLogger.logging(channel_id, name, url_id, objectId, "扫描到一条视频", "2001", log_data)
  103. # if status:
  104. # AliyunLogger.logging(channel_id, name, url_id, objectId, "该视频已改造过", "2002", log_data)
  105. # continue
  106. # video_percent = '%.2f' % (share_cnt / like_cnt)
  107. # special = float(0.25)
  108. # if like_cnt >= 30000 or like_cnt >= 50000 or (share_cnt >= 300 and float(video_percent) >= special):
  109. # if int(duration) < 30 or int(duration) > 720:
  110. # AliyunLogger.logging(channel_id, name, url, objectId, "不符合规则:时长不符合规则大于720秒/小于30秒",
  111. # "2003", log_data)
  112. #
  113. # continue
  114. # all_data = {"video_id": objectId, "cover": cover, "video_url": video_url, "rule": video_percent, "old_title": old_title, "decode_key": decode_key}
  115. # list.append(all_data)
  116. # AliyunLogger.logging(channel_id, name, url_id, objectId, "符合规则等待改造", "2004", log_data)
  117. # if len(list) == int(number):
  118. # return list
  119. # else:
  120. # AliyunLogger.logging(channel_id, name, url_id, objectId, "不符合规则:点赞小于30000/50000 或 分享/点赞小于0.25和分享小于300", "2003", log_data)
  121. # continue
  122. # return list
  123. # except Exception as e:
  124. # print(e)
  125. # return list
  126. #
  127. #
  128. # if __name__ == '__main__':
  129. # SPH.get_sph_url('1',"人民日报",'10','2',"视频号",'视频号品类账号')