xng_zhanghao.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import json
  2. import os
  3. import random
  4. import subprocess
  5. import sys
  6. import time
  7. import uuid
  8. import requests
  9. from datetime import datetime, timedelta
  10. from appium import webdriver
  11. from appium.webdriver.extensions.android.nativekey import AndroidKey
  12. from appium.webdriver.common.touch_action import TouchAction
  13. from bs4 import BeautifulSoup
  14. from selenium.common.exceptions import NoSuchElementException
  15. from selenium.webdriver.common.by import By
  16. from application.common.redis.xng_redis import xng_get_video_data
  17. import schedule
  18. class XNGZH(object):
  19. def save_pq_uid(self, content):
  20. current_time = datetime.now()
  21. time_after_10_minutes = current_time + timedelta(minutes=5)
  22. # 获取时间戳
  23. timestamp_seconds = time_after_10_minutes.timestamp()
  24. timestamp_milliseconds = int(timestamp_seconds * 1000)
  25. url = "https://admin.piaoquantv.com/manager/crawler/v3/task/save?muid=999"
  26. payload = {
  27. "taskName": "小年糕账号",
  28. "source": "xiaoniangao",
  29. "mode": "author",
  30. "modeValue": "0",
  31. "modeBoard": "0",
  32. "spiderName": "run_xng_author",
  33. "startTime": timestamp_milliseconds,
  34. "interval": 4800,
  35. "uid": str(content),
  36. "machine": "aliyun",
  37. "rule": [{"period": {"min": 15, "max": 3}},
  38. {"duration": {"min": 50, "max": 0}},
  39. {"share_cnt": {"min": 2, "max": 0}},
  40. {"videos_cnt": {"min": 300, "max": 0}}],
  41. "id": 21
  42. }
  43. headers = {
  44. 'accept': 'application/json',
  45. 'accept-language': 'zh-CN,zh;q=0.9',
  46. 'content-type': 'application/json;',
  47. 'cookie': 'SESSION=YWNiZDg0YWUtNDNhZS00MmRkLTk1YmEtZjY1N2M5NDNlMGRi',
  48. 'origin': 'https://admin.piaoquantv.com',
  49. 'priority': 'u=1, i',
  50. 'sec-ch-ua': '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
  51. 'sec-ch-ua-mobile': '?0',
  52. 'sec-ch-ua-platform': '"macOS"',
  53. 'sec-fetch-dest': 'empty',
  54. 'sec-fetch-mode': 'cors',
  55. 'sec-fetch-site': 'same-origin',
  56. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
  57. }
  58. requests.request("POST", url, headers=headers, json=payload)
  59. def get_tag_id(self, date_int):
  60. for i in range(3):
  61. url = f"https://admin.piaoquantv.com/manager/user/up/searchUserTypeTag?keyword={date_int}&muid=7?muid=999"
  62. payload = {}
  63. headers = {
  64. 'content-length': '0',
  65. 'cookie': 'SESSION=YjM4YmE5NDgtMjJmNi00NjA1LTgyNDUtYTNlZGVlOGNmODMy',
  66. 'origin': 'https://admin.piaoquantv.com',
  67. 'priority': 'u=1, i',
  68. 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
  69. 'sec-ch-ua-mobile': '?0',
  70. 'sec-ch-ua-platform': '"macOS"'
  71. }
  72. response = requests.request("POST", url, headers=headers, data=payload)
  73. response = response.json()
  74. content = response["content"]
  75. if content:
  76. tagId = content[0]['tagId']
  77. return tagId
  78. else:
  79. url = f"https://admin.piaoquantv.com/manager/user/up/createUserTypeTag?tagName={date_int}&muid=7?muid=999"
  80. response = requests.request("POST", url, headers=headers, data=payload)
  81. response = response.json()
  82. content = response["content"]
  83. if content:
  84. tagId = content['tagId']
  85. return tagId
  86. def insert_number(self, mid, tag_id):
  87. for i in range(3):
  88. url = "https://admin.piaoquantv.com/manager/crawler/v3/user/save?muid=999"
  89. payload = {
  90. "source": "xiaoniangao",
  91. "mode": "author",
  92. "modeValue": "",
  93. "modeBoard": "",
  94. "recomStatus": -6,
  95. "appRecomStatus": -6,
  96. "autoAuditStatus": 0,
  97. "tag": f"459,454,106,8240,{int(tag_id)}",
  98. "contentCategory": 0,
  99. "link": str(mid)
  100. }
  101. headers = {
  102. 'content-length': '0',
  103. 'cookie': 'SESSION=YjM4YmE5NDgtMjJmNi00NjA1LTgyNDUtYTNlZGVlOGNmODMy',
  104. 'origin': 'https://admin.piaoquantv.com',
  105. 'priority': 'u=1, i',
  106. 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
  107. 'sec-ch-ua-mobile': '?0',
  108. 'sec-ch-ua-platform': '"macOS"'
  109. }
  110. response = requests.request("POST", url, headers=headers, json=payload)
  111. response = response.json()
  112. code = response["code"]
  113. if code == 0:
  114. print("添加账号成功")
  115. time.sleep(1)
  116. url = "https://admin.piaoquantv.com/manager/crawler/v3/user/list?muid=999"
  117. payload = {
  118. "pageNum": 1,
  119. "pageSize": 20
  120. }
  121. response = requests.request("POST", url, headers=headers, json=payload)
  122. response = response.json()
  123. list = response["content"]['list']
  124. link = list[0]["link"]
  125. if link == str(mid):
  126. print("获取站内账号ID成功")
  127. return list[0]["uid"]
  128. def get_video_info_2(self):
  129. mid_list = []
  130. while True:
  131. mid = xng_get_video_data()
  132. if mid:
  133. json_data = json.loads(mid.decode('utf-8'))
  134. mid = json_data["mid"]
  135. mid_list.append(mid)
  136. else:
  137. break
  138. if mid_list:
  139. current_time = datetime.now()
  140. formatted_time = current_time.strftime("%Y%m%d")
  141. date_int = int(formatted_time)
  142. tag_id = self.get_tag_id(date_int)
  143. mid_list = list(set(mid_list))
  144. for m_id in mid_list:
  145. time.sleep(2)
  146. print(tag_id)
  147. # 新增账号
  148. pq_uid = self.insert_number(m_id, tag_id)
  149. if pq_uid:
  150. file_path = '/root/automatic_crawler/spider/crawler_offline/xng_zh.txt'
  151. with open(file_path, 'r') as file:
  152. content = file.read()
  153. if content and content[-1] != ',':
  154. pq_uid = ',' + str(pq_uid)
  155. with open(file_path, 'a') as file:
  156. file.write(pq_uid)
  157. with open(file_path, 'r') as file:
  158. content = file.read()
  159. time.sleep(1)
  160. self.save_pq_uid(content)
  161. print("成功")
  162. if __name__ == '__main__':
  163. x = XNGZH()
  164. x.get_video_info_2() # 调用任务调度函数