auto_getoff_videos.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. """
  2. @author: luojunhui
  3. """
  4. import time
  5. import requests
  6. import pymysql
  7. import pandas as pd
  8. class AutoGetOffVideos(object):
  9. """
  10. 自动下架视频
  11. """
  12. @classmethod
  13. def get_long_articles_video_list(cls):
  14. """
  15. 获取长文视频list
  16. :return:
  17. """
  18. spider_connection = pymysql.connect(
  19. host="rm-bp1159bu17li9hi94.mysql.rds.aliyuncs.com",
  20. port=3306,
  21. user="crawler",
  22. passwd="crawler123456@",
  23. db="piaoquan-crawler",
  24. charset="utf8mb4"
  25. )
  26. now_time_stamp = int(time.time())
  27. three_days_stamp = now_time_stamp - 3 * 24 * 60 * 60
  28. seven_days_stamp = now_time_stamp - 7 * 24 * 60 * 60
  29. select_sql = f"""
  30. SELECT recall_video_id1, recall_video_id2, recall_video_id3
  31. FROM long_articles_video
  32. WHERE request_time_stamp > %s;
  33. """
  34. cursor = spider_connection.cursor()
  35. cursor.execute(select_sql, seven_days_stamp)
  36. data = cursor.fetchall()
  37. vid_set = set()
  38. for item in data:
  39. for vid in item:
  40. if vid:
  41. vid_set.add(vid)
  42. return tuple(vid_set)
  43. @classmethod
  44. def find_video_play_count(cls, vid_tuple):
  45. """
  46. 获取视频的播放次数
  47. :return:
  48. """
  49. wx_video_connection = pymysql.connect(
  50. host="rr-bp1x9785e8h5452bi157.mysql.rds.aliyuncs.com",
  51. port=3306,
  52. user="wx2016_longvideo",
  53. passwd="wx2016_longvideoP@assword1234",
  54. db="longvideo",
  55. charset="utf8mb4"
  56. )
  57. sql = f"""select id, title, play_count, play_count_total from wx_video where id in {vid_tuple};"""
  58. cursor = wx_video_connection.cursor()
  59. cursor.execute(sql)
  60. data = cursor.fetchall()
  61. result = [
  62. {
  63. "video_id": item[0],
  64. "title": item[1],
  65. "play_count": item[2],
  66. "play_total_count": item[3]
  67. }
  68. for item in data
  69. ]
  70. return result
  71. @classmethod
  72. def change_status(cls, video_id):
  73. """
  74. 修改视频规则
  75. :return:
  76. """
  77. url = "https://admin.piaoquantv.com/manager/video/audit/v2/updateAuditStatus"
  78. params = {
  79. "videoId": video_id,
  80. "auditStatus": 2,
  81. "updateReasonJson": "",
  82. "rejectReasonJson": [
  83. {
  84. "reason": "测试自动下架",
  85. "reasonId": -1
  86. }
  87. ],
  88. "adminUid": 206
  89. }
  90. headers = {
  91. 'accept': 'application/json',
  92. 'accept-language': 'en,zh;q=0.9,zh-CN;q=0.8',
  93. 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
  94. 'cookie': 'SESSION=NTljNTg2YjktMTU0MC00YWQ5LWE4ZTktNDFhODY0NzM3NTcx',
  95. 'origin': 'https://admin.piaoquantv.com',
  96. 'priority': 'u=1, i',
  97. 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
  98. 'sec-ch-ua-mobile': '?0',
  99. 'sec-ch-ua-platform': '"macOS"',
  100. 'sec-fetch-dest': 'empty',
  101. 'sec-fetch-mode': 'cors',
  102. 'sec-fetch-site': 'same-origin',
  103. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'
  104. }
  105. response = requests.request(
  106. "POST",
  107. url,
  108. headers=headers,
  109. params=params
  110. )
  111. return response.json()
  112. if __name__ == '__main__':
  113. AGOV = AutoGetOffVideos()
  114. vid_set = AGOV.get_long_articles_video_list()
  115. result = AGOV.find_video_play_count(vid_set)
  116. for i in result:
  117. print(i)