functions.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. """
  2. @author: luojunhui
  3. """
  4. from datetime import datetime, timedelta
  5. import requests
  6. import json
  7. import oss2
  8. from uuid import uuid4
  9. def generate_daily_strings(start_date, end_date):
  10. """
  11. Generate daily date_str
  12. :param start_date:
  13. :param end_date:
  14. :return:
  15. """
  16. start = datetime.strptime(start_date, "%Y%m%d")
  17. end = datetime.strptime(end_date, "%Y%m%d")
  18. current = start
  19. date_strings = []
  20. while current <= end:
  21. date_strings.append(current.strftime("%Y%m%d"))
  22. current += timedelta(days=1)
  23. return date_strings
  24. def whisper(video_id):
  25. """
  26. input video_id, output video_text
  27. :param video_id:
  28. :return:
  29. """
  30. url = "http://61.48.133.26:5999/video_to_text"
  31. body = {
  32. "video_id": video_id
  33. }
  34. header = {
  35. "Content-Type": "application/json",
  36. }
  37. response = requests.post(
  38. url=url,
  39. json=body,
  40. headers=header
  41. )
  42. return response.json()
  43. def get_text(video_id):
  44. """
  45. input video_id, output video_text
  46. :param video_id:
  47. :return:
  48. """
  49. url = "http://localhost:8888/get_text"
  50. body = {
  51. "vid": video_id
  52. }
  53. header = {
  54. "Content-Type": "application/json",
  55. }
  56. response = requests.post(
  57. url=url,
  58. json=body,
  59. headers=header
  60. )
  61. return response.json()
  62. def auto_upload_aigc():
  63. """
  64. auto publish
  65. :return:
  66. """
  67. url = "http://aigc-api.cybertogether.net/aigc/crawler/plan/save"
  68. payload = json.dumps({
  69. "params": {
  70. "contentFilters": [],
  71. "accountFilters": [],
  72. "filterAccountMatchMode": 1,
  73. "filterContentMatchMode": 1,
  74. "selectModeValues": [],
  75. "imageSearchModeValues": [],
  76. "contentModal": 3,
  77. "analyze": {},
  78. "crawlerComment": 0,
  79. "inputGroup": [
  80. [
  81. {
  82. "inputValue": [
  83. {
  84. "fileName": "pqzf.png",
  85. "ossKey": "upload/03bf695277827c2387133a1ac9290fd2.png",
  86. "type": "image/png",
  87. "size": 2978
  88. }
  89. ],
  90. "fieldName": "cover",
  91. "fieldType": 1,
  92. "groupId": "fa9557a13208975a893777188f9e4b28"
  93. },
  94. {
  95. "fieldName": "title",
  96. "fieldType": 0,
  97. "groupId": "fa9557a13208975a893777188f9e4b28",
  98. "inputValue": "412412412"
  99. },
  100. {
  101. "fieldName": "content",
  102. "fieldType": 0,
  103. "groupId": "fa9557a13208975a893777188f9e4b28",
  104. "inputValue": "12312442"
  105. },
  106. {
  107. "fieldName": "image",
  108. "fieldType": 1,
  109. "groupId": "fa9557a13208975a893777188f9e4b28",
  110. "inputValue": [
  111. {
  112. "fileName": "lehuo.png",
  113. "ossKey": "upload/4bf6db57ccd1629909e070833aab8878.png",
  114. "type": "image/png",
  115. "size": 5085
  116. }
  117. ]
  118. },
  119. {
  120. "fieldName": "video",
  121. "fieldType": 2,
  122. "groupId": "fa9557a13208975a893777188f9e4b28"
  123. },
  124. {
  125. "fieldName": "audio",
  126. "fieldType": 3,
  127. "groupId": "fa9557a13208975a893777188f9e4b28"
  128. },
  129. {
  130. "fieldName": "tag",
  131. "fieldType": 0,
  132. "groupId": "fa9557a13208975a893777188f9e4b28"
  133. }
  134. ]
  135. ],
  136. "inputSourceGroups": [],
  137. "modePublishTime": [],
  138. "name": "junhui测试自动上传_by_python",
  139. "frequencyType": 3,
  140. "planType": 2
  141. },
  142. "baseInfo": {
  143. "token": "af54cdc404c3464d896745df389b2dce",
  144. "appType": 9,
  145. "platform": "pc",
  146. "appVersionCode": 1000,
  147. "clientTimestamp": 1,
  148. "fid": 1,
  149. "loginUid": 1,
  150. "pageSource": 1,
  151. "requestId": 1,
  152. "rid": 1,
  153. "uid": 1
  154. }
  155. })
  156. headers = {
  157. 'Accept': 'application/json',
  158. 'Accept-Language': 'en,zh;q=0.9,zh-CN;q=0.8',
  159. 'Content-Type': 'application/json',
  160. 'Origin': 'http://aigc-admin.cybertogether.net',
  161. 'Proxy-Connection': 'keep-alive',
  162. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36'
  163. }
  164. response = requests.request("POST", url, headers=headers, data=payload)
  165. print(response.text)
  166. def upload_to_oss(local_path):
  167. """
  168. 上传到oss
  169. :return:
  170. """
  171. oss_video_key = str(uuid4())
  172. access_key_id = "LTAIP6x1l3DXfSxm"
  173. access_key_secret = "KbTaM9ars4OX3PMS6Xm7rtxGr1FLon"
  174. endpoint = "oss-cn-hangzhou.aliyuncs.com"
  175. bucket_name = "art-pubbucket"
  176. bucket = oss2.Bucket(
  177. oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name
  178. )
  179. bucket.put_object_from_file(key=oss_video_key, filename=local_path)
  180. return oss_video_key