common.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. # encoding: utf-8
  2. """
  3. @author: luojunhui
  4. """
  5. import time
  6. import json
  7. import uuid
  8. import random
  9. import hashlib
  10. import requests
  11. import aiohttp
  12. import urllib.parse
  13. def create_gzh_path(video_id, shared_uid):
  14. """
  15. :param video_id: 视频 id
  16. :param shared_uid: 分享 id
  17. """
  18. def auto_white(root_share_id_):
  19. """
  20. 自动加入白名单, 保证公众号百分百出广告
  21. :param root_share_id_:
  22. :return:
  23. """
  24. def get_cookie():
  25. """
  26. 获取 cookie
  27. :return:
  28. """
  29. url = "https://admin.piaoquantv.com/manager/login?account=luojunhui&passWd=e10adc3949ba59abbe56e057f20f883e&muid=7"
  30. payload = {}
  31. headers = {
  32. 'accept': 'application/json, text/plain, */*',
  33. 'accept-language': 'en',
  34. 'priority': 'u=1, i',
  35. 'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
  36. 'sec-ch-ua-mobile': '?0',
  37. 'sec-ch-ua-platform': '"macOS"',
  38. 'sec-fetch-dest': 'empty',
  39. 'sec-fetch-mode': 'cors',
  40. 'sec-fetch-site': 'same-origin',
  41. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
  42. }
  43. response = requests.request("GET", url, headers=headers, data=payload)
  44. return response.cookies.values()[0]
  45. url = "https://admin.piaoquantv.com/manager/ad/own/white/rootShare/save"
  46. dd = {
  47. "rootShareId": root_share_id_,
  48. "commit": "算法自动加入白名单--"
  49. }
  50. payload = json.dumps(dd)
  51. cookie = get_cookie()
  52. headers = {
  53. 'accept': 'application/json',
  54. 'accept-language': 'en',
  55. 'content-type': 'application/json;',
  56. 'cookie': "SESSION=" + cookie,
  57. 'origin': 'https://admin.piaoquantv.com',
  58. 'priority': 'u=1, i',
  59. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
  60. }
  61. response = requests.request("POST", url, headers=headers, data=payload)
  62. return response.json()['content']
  63. def generate_source_id():
  64. """
  65. generate_source_id
  66. :return:
  67. """
  68. timestamp = str(int(time.time() * 1000))
  69. random_str = str(random.randint(1000, 9999))
  70. hash_input = f"{timestamp}-{random_str}"
  71. return hashlib.md5(hash_input.encode()).hexdigest()
  72. root_share_id = str(uuid.uuid4())
  73. source_id = "longArticles_" + generate_source_id()
  74. url = f"pages/user-videos?id={video_id}&su={shared_uid}&fromGzh=1&rootShareId={root_share_id}&shareId={root_share_id}&rootSourceId={source_id}"
  75. # 自动把 root_share_id 加入到白名单
  76. # auto_white(root_share_id)
  77. return root_share_id, source_id, f"pages/category?jumpPage={urllib.parse.quote(url, safe='')}"
  78. def request_for_info(video_id):
  79. """
  80. 请求数据
  81. :param video_id:
  82. :return:
  83. """
  84. url = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo"
  85. data = {
  86. "videoIdList": [video_id]
  87. }
  88. header = {
  89. "Content-Type": "application/json",
  90. }
  91. response = requests.post(url, headers=header, data=json.dumps(data))
  92. return response.json()
  93. def clean_title(strings):
  94. """
  95. :param strings:
  96. :return:
  97. """
  98. return (
  99. strings.strip()
  100. .replace("\n", "")
  101. .replace("/", "")
  102. .replace("\r", "")
  103. .replace("#", "")
  104. .replace(".", "。")
  105. .replace("\\", "")
  106. .replace("&NBSP", "")
  107. .replace(":", "")
  108. .replace("*", "")
  109. .replace("?", "")
  110. .replace("?", "")
  111. .replace('"', "")
  112. .replace("<", "")
  113. .replace(">", "")
  114. .replace("|", "")
  115. .replace(" ", "")
  116. .replace('"', "")
  117. .replace("'", "")
  118. )
  119. def sensitive_flag(s_words, ori_title):
  120. """
  121. :param s_words:
  122. :param ori_title:
  123. :return:
  124. """
  125. for word in s_words:
  126. if str(word) in ori_title:
  127. return False
  128. return True
  129. def account_info_map(gh_id):
  130. """
  131. 根据账号 id 来判断返回哪个小程序账号
  132. :param gh_id:
  133. :return:
  134. """
  135. pqlh = {
  136. "name": "票圈乐活",
  137. "id": "wxe8f8f0e23cecad0f",
  138. "avatar": "https://rescdn.yishihui.com/0temp/lehuo.png"
  139. }
  140. xyfxhyjl = {
  141. "name": "幸运福星好运锦鲤",
  142. "id": "wx95dcbfc0753c06a8",
  143. "avatar": "https://rescdn.yishihui.com/0temp/xyfxhyjl.png"
  144. }
  145. pqzf = {
  146. "name": "票圈祝福",
  147. "id": "wxf7261ed54f2e450e",
  148. "avatar": "https://rescdn.yishihui.com/0temp/pqzf.png"
  149. }
  150. buy_accounts = [
  151. "gh_084a485e859a",
  152. "gh_e24da99dc899",
  153. "gh_e0eb490115f5",
  154. "gh_183d80deffb8",
  155. "gh_5ff48e9fb9ef",
  156. "gh_9f8dc5b0c74e",
  157. "gh_6d9f36e3a7be"
  158. ]
  159. dyy = [
  160. "gh_9877c8541764",
  161. "gh_6d205db62f04",
  162. "gh_c69776baf2cd",
  163. "gh_7e5818b2dd83",
  164. "gh_89ef4798d3ea",
  165. "gh_a2901d34f75b",
  166. "gh_b15de7c99912"
  167. ]
  168. if gh_id in buy_accounts:
  169. return ""
  170. elif gh_id in dyy:
  171. return ""
  172. else:
  173. return ""
  174. async def request_etl(url, headers, json_data):
  175. """
  176. 异步请求ETL
  177. :return:
  178. """
  179. async with aiohttp.ClientSession() as session:
  180. async with session.post(url, headers=headers, json=json_data, timeout=60) as response:
  181. response_data = await response.json()
  182. return response_data