common.py 4.9 KB

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