123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- import json
- import os
- import random
- import subprocess
- import sys
- import time
- import uuid
- import requests
- from datetime import datetime, timedelta
- from appium import webdriver
- from appium.webdriver.extensions.android.nativekey import AndroidKey
- from appium.webdriver.common.touch_action import TouchAction
- from bs4 import BeautifulSoup
- from selenium.common.exceptions import NoSuchElementException
- from selenium.webdriver.common.by import By
- from application.common.redis.xng_redis import xng_get_video_data
- import schedule
- class XNGZH(object):
- def save_pq_uid(self, content):
- current_time = datetime.now()
- time_after_10_minutes = current_time + timedelta(minutes=5)
- # 获取时间戳
- timestamp_seconds = time_after_10_minutes.timestamp()
- timestamp_milliseconds = int(timestamp_seconds * 1000)
- url = "https://admin.piaoquantv.com/manager/crawler/v3/task/save?muid=999"
- payload = {
- "taskName": "小年糕账号",
- "source": "xiaoniangao",
- "mode": "author",
- "modeValue": "0",
- "modeBoard": "0",
- "spiderName": "run_xng_author",
- "startTime": timestamp_milliseconds,
- "interval": 4800,
- "uid": str(content),
- "machine": "aliyun",
- "rule": [{"period": {"min": 15, "max": 3}},
- {"duration": {"min": 50, "max": 0}},
- {"share_cnt": {"min": 2, "max": 0}},
- {"videos_cnt": {"min": 300, "max": 0}}],
- "id": 21
- }
- headers = {
- 'accept': 'application/json',
- 'accept-language': 'zh-CN,zh;q=0.9',
- 'content-type': 'application/json;',
- 'cookie': 'SESSION=YWNiZDg0YWUtNDNhZS00MmRkLTk1YmEtZjY1N2M5NDNlMGRi',
- 'origin': 'https://admin.piaoquantv.com',
- 'priority': 'u=1, i',
- 'sec-ch-ua': '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"macOS"',
- 'sec-fetch-dest': 'empty',
- 'sec-fetch-mode': 'cors',
- 'sec-fetch-site': 'same-origin',
- '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'
- }
- requests.request("POST", url, headers=headers, json=payload)
- def get_tag_id(self, date_int):
- for i in range(3):
- url = f"https://admin.piaoquantv.com/manager/user/up/searchUserTypeTag?keyword={date_int}&muid=7?muid=999"
- payload = {}
- headers = {
- 'content-length': '0',
- 'cookie': 'SESSION=YjM4YmE5NDgtMjJmNi00NjA1LTgyNDUtYTNlZGVlOGNmODMy',
- 'origin': 'https://admin.piaoquantv.com',
- 'priority': 'u=1, i',
- 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"macOS"'
- }
- response = requests.request("POST", url, headers=headers, data=payload)
- response = response.json()
- content = response["content"]
- if content:
- tagId = content[0]['tagId']
- return tagId
- else:
- url = f"https://admin.piaoquantv.com/manager/user/up/createUserTypeTag?tagName={date_int}&muid=7?muid=999"
- response = requests.request("POST", url, headers=headers, data=payload)
- response = response.json()
- content = response["content"]
- if content:
- tagId = content['tagId']
- return tagId
- def insert_number(self, mid, tag_id):
- for i in range(3):
- url = "https://admin.piaoquantv.com/manager/crawler/v3/user/save?muid=999"
- payload = {
- "source": "xiaoniangao",
- "mode": "author",
- "modeValue": "",
- "modeBoard": "",
- "recomStatus": -6,
- "appRecomStatus": -6,
- "autoAuditStatus": 0,
- "tag": f"459,454,106,8240,{int(tag_id)}",
- "contentCategory": 0,
- "link": str(mid)
- }
- headers = {
- 'content-length': '0',
- 'cookie': 'SESSION=YjM4YmE5NDgtMjJmNi00NjA1LTgyNDUtYTNlZGVlOGNmODMy',
- 'origin': 'https://admin.piaoquantv.com',
- 'priority': 'u=1, i',
- 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
- 'sec-ch-ua-mobile': '?0',
- 'sec-ch-ua-platform': '"macOS"'
- }
- response = requests.request("POST", url, headers=headers, json=payload)
- response = response.json()
- code = response["code"]
- if code == 0:
- print("添加账号成功")
- time.sleep(1)
- url = "https://admin.piaoquantv.com/manager/crawler/v3/user/list?muid=999"
- payload = {
- "pageNum": 1,
- "pageSize": 20
- }
- response = requests.request("POST", url, headers=headers, json=payload)
- response = response.json()
- list = response["content"]['list']
- link = list[0]["link"]
- if link == str(mid):
- print("获取站内账号ID成功")
- return list[0]["uid"]
- def get_video_info_2(self):
- mid_list = []
- while True:
- mid = xng_get_video_data()
- if mid:
- json_data = json.loads(mid.decode('utf-8'))
- mid = json_data["mid"]
- mid_list.append(mid)
- else:
- break
- if mid_list:
- current_time = datetime.now()
- formatted_time = current_time.strftime("%Y%m%d")
- date_int = int(formatted_time)
- tag_id = self.get_tag_id(date_int)
- mid_list = list(set(mid_list))
- for m_id in mid_list:
- time.sleep(2)
- print(tag_id)
- # 新增账号
- pq_uid = self.insert_number(m_id, tag_id)
- if pq_uid:
- file_path = '/root/automatic_crawler/spider/crawler_offline/xng_zh.txt'
- with open(file_path, 'r') as file:
- content = file.read()
- if content and content[-1] != ',':
- pq_uid = ',' + str(pq_uid)
- with open(file_path, 'a') as file:
- file.write(pq_uid)
- with open(file_path, 'r') as file:
- content = file.read()
- time.sleep(1)
- self.save_pq_uid(content)
- print("成功")
- if __name__ == '__main__':
- x = XNGZH()
- x.get_video_info_2() # 调用任务调度函数
|