sph_nrxs.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import random
  2. import time
  3. import requests
  4. import json
  5. import re
  6. from common import Material, Feishu, Common
  7. from common.sql_help import sqlCollect
  8. class SphNrxs:
  9. """创建票圈账号"""
  10. @classmethod
  11. def insert_number(cls, mid):
  12. for i in range(3):
  13. url = "https://admin.piaoquantv.com/manager/crawler/v3/user/save"
  14. payload = {
  15. "source": "jiqizidonggaizao",
  16. "mode": "author",
  17. "modeValue": "",
  18. "modeBoard": "",
  19. "recomStatus": -7,
  20. "appRecomStatus": -7,
  21. "autoAuditStatus": 0,
  22. "tag": f"7592,452,8776,467",
  23. "contentCategory": 0,
  24. "link": str(mid)
  25. }
  26. cookie = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "票圈后台-cookie")
  27. headers = {
  28. 'content-length': '0',
  29. 'cookie': cookie,
  30. 'origin': 'https://admin.piaoquantv.com',
  31. 'priority': 'u=1, i',
  32. 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
  33. 'sec-ch-ua-mobile': '?0',
  34. 'sec-ch-ua-platform': '"macOS"'
  35. }
  36. response = requests.request("POST", url, headers=headers, json=payload)
  37. response = response.json()
  38. code = response["code"]
  39. if code == 0:
  40. print("添加账号成功")
  41. time.sleep(1)
  42. url = "https://admin.piaoquantv.com/manager/crawler/v3/user/list"
  43. payload = {
  44. "pageNum": 1,
  45. "pageSize": 20
  46. }
  47. response = requests.request("POST", url, headers=headers, json=payload)
  48. response = response.json()
  49. list = response["content"]['list']
  50. link = list[0]["link"]
  51. if link == str(mid):
  52. print("获取站内账号ID成功")
  53. return list[0]["uid"]
  54. else:
  55. if code == '10010':
  56. return None
  57. Feishu.bot("xinxin", '票圈后台提醒', f'票圈后台cookie 失效了,请及时更换', 'xinxin')
  58. """腾讯互选平台通过appid获取观众画像"""
  59. @classmethod
  60. def get_hx(cls, aid):
  61. url = "http://8.217.190.241:8888/crawler/wei_xin/shi_pin_hao/hu_xuan_detail"
  62. cookie = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "腾讯互选平台-cookie")
  63. account_id = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "腾讯互选平台-account_id")
  64. payload = json.dumps({
  65. "account_id": aid,
  66. "uid": str(account_id),
  67. "cookie": cookie
  68. })
  69. headers = {
  70. 'Content-Type': 'application/json'
  71. }
  72. response = requests.request("POST", url, headers=headers, data=payload)
  73. response = response.json()
  74. ret = response['code']
  75. if ret == 0:
  76. data = response['data']['data']
  77. if data:
  78. age_ranges = ['<18 岁', '18 ~ 24 岁', '25 ~ 29 岁', '30 ~ 39 岁', '40 ~ 49 岁', '>50 岁']
  79. viewer_portrait = data['viewer_portrait'] # 观众画像
  80. # 找到占比最大的项
  81. viewer_max_age_range = max(
  82. (item for item in viewer_portrait if item['name'] in age_ranges),
  83. key=lambda x: float(x['percentage'].strip('%'))
  84. )
  85. if viewer_max_age_range['name'] != '>50 岁':
  86. return "2"
  87. fans_portrait = data['fans_portrait'] # 粉丝画像
  88. # 找到占比最大的项
  89. fans_max_age_range = max(
  90. (item for item in fans_portrait if item['name'] in age_ranges),
  91. key=lambda x: float(x['percentage'].strip('%'))
  92. )
  93. if fans_max_age_range['name'] != '>50 岁':
  94. return "3"
  95. return "0"
  96. else:
  97. Feishu.bot("xinxin", '腾讯互选平台提醒', f'腾讯互选平台cookie 失效了,请及时更换', 'xinxin')
  98. return None
  99. """腾讯互选平台通过搜索获取appid"""
  100. @classmethod
  101. def get_hxpt_appid(cls, user):
  102. url = "https://huxuan.qq.com/cgi-bin/advertiser/finder_publisher/search"
  103. cookie = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "腾讯互选平台-cookie")
  104. account_id = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "腾讯互选平台-account_id")
  105. payload = json.dumps({
  106. "keyword": user,
  107. "page": {
  108. "no": 1,
  109. "size": 50
  110. }
  111. })
  112. headers = {
  113. 'Accept': 'application/json, text/plain, */*',
  114. 'Accept-Language': 'zh-CN,zh;q=0.9',
  115. 'Cache-Control': 'no-cache',
  116. 'Connection': 'keep-alive',
  117. 'Content-Type': 'application/json',
  118. 'Cookie': cookie,
  119. 'Origin': 'https://huxuan.qq.com',
  120. 'Pragma': 'no-cache',
  121. 'Referer': 'https://huxuan.qq.com/trade/selection/46251713/selection_list?type=finder-trade',
  122. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
  123. 'account_id': str(account_id),
  124. 'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
  125. 'sec-ch-ua-mobile': '?0',
  126. 'sec-ch-ua-platform': '"macOS"'
  127. }
  128. for i in range(3):
  129. response = requests.request("POST", url, headers=headers, data=payload)
  130. response = response.json()
  131. ret = response['ret']
  132. if ret == 0:
  133. try:
  134. appid = response['data']['item'][0]['appid']
  135. if appid:
  136. return appid
  137. except Exception as e:
  138. Common.logger("sph_nrxs").info(f"{user}获取腾讯互选平台appid异常,异常信息{e}")
  139. continue
  140. else:
  141. Feishu.bot("xinxin", '腾讯互选平台提醒', f'腾讯互选平台cookie 失效了,请及时更换', 'xinxin')
  142. return None
  143. return None
  144. """获取用户主页是否符合规则"""
  145. @classmethod
  146. def get_sph_data(cls, user, uid):
  147. url = "http://61.48.133.26:30001/FinderGetUpMasterNextPage"
  148. headers = {
  149. 'Content-Type': 'application/json'
  150. }
  151. payload = json.dumps({
  152. "username": user,
  153. "last_buffer": ""
  154. })
  155. response = requests.request("POST", url, headers=headers, data=payload)
  156. time.sleep(random.randint(1, 5))
  157. if response.text == "" or response.text == None:
  158. return
  159. res_json = response.json()
  160. try:
  161. if len(res_json["DownloadAddress"]) == 0 or res_json["DownloadAddress"] == "" or res_json[
  162. "DownloadAddress"] == None:
  163. return
  164. except:
  165. pass
  166. if "objectId" not in response.text or response.status_code != 200:
  167. return
  168. if len(res_json["UpMasterHomePage"]) == 0:
  169. return
  170. if not res_json["UpMasterHomePage"]:
  171. return
  172. try:
  173. for obj in res_json["UpMasterHomePage"]:
  174. Common.logger("sph_nrxs").info(f"{user}扫描到一条数据")
  175. objectId = obj['objectId']
  176. object_id = sqlCollect.sph_data_info_v_id(objectId, "视频号")
  177. if object_id:
  178. continue
  179. objectNonceId = obj['objectNonceId']
  180. url1 = "http://61.48.133.26:30001/GetFinderDownloadAddress"
  181. payload = json.dumps({
  182. "objectId": objectId,
  183. "objectNonceId": objectNonceId
  184. })
  185. headers = {
  186. 'Content-Type': 'text/plain'
  187. }
  188. response = requests.request("POST", url1, headers=headers, data=payload)
  189. time.sleep(random.randint(0, 1))
  190. video_obj = response.json()
  191. video_url = video_obj.get('DownloadAddress')
  192. if len(video_url) == 0:
  193. continue
  194. duration = video_obj.get('play_len')
  195. # cover = video_obj.get('thumb_url')
  196. share_cnt = int(obj['forward_count']) # 分享
  197. like_cnt = int(obj['like_count']) # 点赞
  198. # user_name = obj['username'] # 用户名标示
  199. nick_name = obj['nickname'] # 用户名
  200. # comment_count = obj['comment_count'] # 评论数
  201. # fav_count = obj['fav_count'] # 大拇指点赞数
  202. video_percent = '%.2f' % (share_cnt / like_cnt)
  203. special = float(0.25)
  204. Common.logger("sph_nrxs").info(
  205. f"扫描:原用户主页名:{uid},溯源用户主页id:{url},视频id{objectId} ,分享:{share_cnt},点赞:{like_cnt} ,时长:{duration},视频链接:{video_url}")
  206. if share_cnt >= 300 and float(video_percent) >= special and int(duration) >= 30:
  207. Common.logger("sph_nrxs").info(f"{nick_name}符合规则")
  208. return nick_name
  209. return None
  210. except Exception as e:
  211. Common.logger("sph_nrxs").info(f"{user}异常,异常信息{e}")
  212. return None
  213. """视频号加热平台相似溯源"""
  214. @classmethod
  215. def get_nrxs_list(cls, uid):
  216. cookie = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "视频号加热")
  217. time.sleep(10)
  218. url = "http://8.217.190.241:8888/crawler/wei_xin/shi_pin_hao/jia_re"
  219. payload = json.dumps({
  220. "account_name": uid,
  221. "category": "推荐",
  222. "cookie": cookie
  223. })
  224. headers = {
  225. 'Content-Type': 'application/json'
  226. }
  227. try:
  228. time.sleep(2)
  229. response = requests.request("POST", url, headers=headers, data=payload)
  230. response = response.json()
  231. code = response['code']
  232. if code == 0:
  233. sqlCollect.update_machine_making_reflux(uid)
  234. data_list = response['data']['data']
  235. if data_list:
  236. for data in data_list:
  237. nick_name = data['nickName'] # 用户名
  238. user_name = data['username'] # 用户v2
  239. status = sqlCollect.select_crawler_uesr_v3(uid)
  240. if status:
  241. pq_id = status[0]
  242. else:
  243. pq_id = cls.insert_number(nick_name)
  244. if pq_id == None:
  245. continue
  246. user = cls.get_sph_data(user_name, uid)
  247. if user:
  248. # time.sleep(180)
  249. # appid = cls.get_hxpt_appid(user)
  250. # if appid:
  251. # time.sleep(180)
  252. # has_used = cls.get_hx(appid)
  253. # if has_used:
  254. # if has_used == '0':
  255. sqlCollect.insert_xssy_sph_info(uid, nick_name, user_name, "0", "", pq_id)
  256. values = [
  257. [
  258. "视频号",
  259. nick_name,
  260. pq_id,
  261. "5",
  262. "通用-分享到群",
  263. "AI片尾引导",
  264. "",
  265. "",
  266. "AI标题",
  267. "",
  268. f"溯源账号:{uid}"
  269. ]
  270. ]
  271. Feishu.insert_columns("WGIYsSDdxhItBwtJ0xgc0yE7nEg", '0701bd', "ROWS", 1, 2)
  272. time.sleep(0.5)
  273. Feishu.update_values("WGIYsSDdxhItBwtJ0xgc0yE7nEg", '0701bd', "B2:Z2",
  274. values)
  275. Feishu.bot("xinxin", '视频号溯源成功提示', f'原账号:{uid},溯源到的账号:{nick_name},写入账号:{pq_id}', 'xinxin')
  276. else:
  277. # sqlCollect.insert_xssy_sph_info(uid, nick_name, user_name, has_used, appid)
  278. sqlCollect.insert_xssy_sph_info(uid, nick_name, user_name, "1")
  279. # else:
  280. # sqlCollect.insert_xssy_sph_info(uid, nick_name, user_name, "1")
  281. # continue
  282. else:
  283. return None
  284. else:
  285. Feishu.bot("xinxin", '视频号加热提醒', f'视频号加热平台 cookie 失效了,请及时更换', 'xinxin')
  286. return None
  287. except Exception as e:
  288. Feishu.bot("xinxin", '视频号加热提醒', f'视频号加热平台 cookie 失效了,请及时更换', 'xinxin')
  289. Common.logger("sph_nrxs").error(f"用户名:{uid}视频号加热bot异常:{e}\n")
  290. return None
  291. """获取需溯源账号"""
  292. @classmethod
  293. def sph_nrxs_data(cls):
  294. user = sqlCollect.get_machine_making_reflux("视频号", "单点视频")
  295. if user == None:
  296. return
  297. user = [item[0] for item in user]
  298. Feishu.bot("xinxin", '视频号溯源提醒', f'今日需溯源账号共{len(user)}条', 'xinxin')
  299. for uid in user:
  300. if re.match(r'^[A-Za-z0-9]+$', uid):
  301. # 匹配成功,进行下一次循环
  302. continue
  303. Feishu.bot("xinxin", '视频号溯源提醒', f'开始溯源账号名称{uid}', 'xinxin')
  304. list = cls.get_nrxs_list(uid)
  305. print(list)
  306. if __name__ == '__main__':
  307. SphNrxs.sph_nrxs_data()