xng_zhanghao.py 6.5 KB

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