common.py 5.3 KB

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