feishu_form.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. # -*- coding: utf-8 -*-
  2. import json
  3. import os
  4. import random
  5. import sys
  6. import datetime
  7. import itertools
  8. from collections import defaultdict
  9. from common.sql_help import sqlCollect
  10. sys.path.append(os.getcwd())
  11. from common.feishu_utils import Feishu
  12. class Material():
  13. """
  14. 获取汇总表所有负责人列表
  15. """
  16. @classmethod
  17. def feishu_list(cls):
  18. summary = Feishu.get_values_batch("summary", "bc154d")
  19. list = []
  20. for row in summary[1:]:
  21. mark = row[0]
  22. name = row[1]
  23. feishu_id = row[3]
  24. feishu_sheet = row[4]
  25. cookie_sheet = row[5]
  26. number = {"mark": mark, "name": name, "feishu_id": feishu_id, "feishu_sheet": feishu_sheet, "cookie_sheet": cookie_sheet}
  27. if mark:
  28. list.append(number)
  29. else:
  30. return list
  31. return list
  32. @classmethod
  33. def get_sph_user(cls):
  34. data = Feishu.get_values_batch("GPbhsb5vchAN3qtzot6cu1f0n1c", "cc7ef0")
  35. user_data_list = []
  36. try:
  37. for row in data[1:]:
  38. users = str(row[2])
  39. if users and users != 'None':
  40. if ',' in users:
  41. user_list = users.split(',')
  42. else:
  43. user_list = [users]
  44. for user in user_list:
  45. status = sqlCollect.sph_channel_user(user)
  46. if status:
  47. user_data_list.append(user)
  48. else:
  49. return user_data_list
  50. return user_data_list
  51. except:
  52. return user_data_list
  53. """
  54. list 重新排序
  55. """
  56. @classmethod
  57. def sort_keyword_data(cls, data):
  58. # 解析 JSON 数据
  59. data = [json.loads(item) for item in data]
  60. # 根据 keyword_name 进行分组
  61. groups = defaultdict(list)
  62. for item in data:
  63. groups[item['keyword_name']].append(item)
  64. # 获取所有唯一的 keyword_name
  65. priority_names = list(groups.keys())
  66. # 对每个分组内的数据按 first_category 进行随机打乱
  67. for name in priority_names:
  68. random.shuffle(groups[name]) # 打乱每个分组内的数据顺序
  69. # 轮流排序每个分组的数据,保持 keyword_name 的顺序
  70. result = []
  71. max_length = max(len(groups[name]) for name in priority_names)
  72. for i in range(max_length):
  73. for name in priority_names:
  74. if i < len(groups[name]):
  75. result.append(groups[name][i])
  76. # 将结果转回 JSON 字符串列表
  77. sorted_list = [json.dumps(item, ensure_ascii=False) for item in result]
  78. return sorted_list
  79. """
  80. 获取搜索任务
  81. """
  82. @classmethod
  83. def get_keyword_data(cls, feishu_id, feishu_sheet):
  84. data = Feishu.get_values_batch(feishu_id, feishu_sheet)
  85. processed_list = []
  86. try:
  87. for row in data[1:]:
  88. channel_id = row[1]
  89. channel_url = str(row[2])
  90. piaoquan_id = row[3]
  91. number = row[4]
  92. video_share = row[5]
  93. video_ending = row[6]
  94. voice = row[7]
  95. crop_tool = row[8]
  96. gg_duration = row[9]
  97. title = row[10]
  98. if channel_url == None or channel_url == "" or len(channel_url) == 0:
  99. continue
  100. first_category = row[12] # 一级品类
  101. secondary_category = row[13] # 二级品类
  102. def count_items(item, separator):
  103. if item and item not in {'None', ''}:
  104. return len(item.split(separator))
  105. return 0
  106. video_id_total = count_items(str(channel_url), ',')
  107. title_total = count_items(str(title), '/')
  108. video_ending_total = count_items(str(video_ending), ',')
  109. values = [channel_id, video_id_total, piaoquan_id, video_share, video_ending_total, crop_tool, gg_duration, title_total, first_category]
  110. filtered_values = [str(value) for value in values if value is not None and value != "None"]
  111. task_mark = "_".join(map(str, filtered_values))
  112. keyword_sort = row[14] # 排序条件
  113. keyword_time = row[15] # 发布时间
  114. keyword_duration = row[16] # 视频时长
  115. keyword_name = row[17] # 负责人
  116. keyword_sort_list = keyword_sort.split(',')
  117. keyword_duration_list = keyword_duration.split(',')
  118. keyword_time_list = keyword_time.split(',')
  119. combinations = list(itertools.product(keyword_sort_list, keyword_time_list, keyword_duration_list))
  120. if ',' in channel_url:
  121. channel_url = channel_url.split(',')
  122. else:
  123. channel_url = [channel_url]
  124. for user in channel_url:
  125. for combo in combinations:
  126. number_dict = {
  127. "task_mark": task_mark,
  128. "channel_id": channel_id,
  129. "channel_url": user,
  130. "piaoquan_id": piaoquan_id,
  131. "number": number,
  132. "title": title,
  133. "video_share": video_share,
  134. "video_ending": video_ending,
  135. "crop_total": crop_tool,
  136. "gg_duration_total": gg_duration,
  137. "voice": voice,
  138. "first_category": first_category, # 一级品类
  139. "secondary_category": secondary_category, # 二级品类
  140. "combo": combo, # 搜索条件
  141. "keyword_name": keyword_name # 品类负责人
  142. }
  143. processed_list.append(json.dumps(number_dict, ensure_ascii=False))
  144. except:
  145. processed_list = cls.sort_keyword_data(processed_list)
  146. return processed_list
  147. processed_list = cls.sort_keyword_data(processed_list)
  148. return processed_list
  149. """
  150. 获取对应负责人任务明细
  151. """
  152. @classmethod
  153. def get_task_data(cls, feishu_id, feishu_sheet):
  154. data = Feishu.get_values_batch(feishu_id, feishu_sheet)
  155. processed_list = []
  156. try:
  157. for row in data[1:]:
  158. channel_id = row[1]
  159. channel_url = str(row[2])
  160. piaoquan_id = row[3]
  161. number = row[4]
  162. video_share = row[5]
  163. video_ending = row[6]
  164. voice = row[7]
  165. crop_tool = row[8]
  166. gg_duration = row[9]
  167. title = row[10]
  168. if channel_url == None or channel_url == "" or len(channel_url) == 0:
  169. continue
  170. try:
  171. ls_number = int(row[11])
  172. except:
  173. ls_number = None
  174. def count_items(item, separator):
  175. if item and item not in {'None', ''}:
  176. return len(item.split(separator))
  177. return 0
  178. video_id_total = count_items(str(channel_url), ',')
  179. title_total = count_items(str(title), '/')
  180. video_ending_total = count_items(str(video_ending), ',')
  181. values = [channel_id, video_id_total, piaoquan_id, video_share, video_ending_total, crop_tool, gg_duration, title_total]
  182. filtered_values = [str(value) for value in values if value is not None and value != "None"]
  183. task_mark = "_".join(map(str, filtered_values))
  184. if piaoquan_id and piaoquan_id not in {'None', ''}:
  185. if ',' in channel_url:
  186. channel_url = channel_url.split(',')
  187. else:
  188. channel_url = [channel_url]
  189. for user in channel_url:
  190. number_dict = {
  191. "task_mark": task_mark,
  192. "channel_id": channel_id,
  193. "channel_url": user,
  194. "piaoquan_id": piaoquan_id,
  195. "number": number,
  196. "title": title,
  197. "video_share": video_share,
  198. "video_ending": video_ending,
  199. "crop_total": crop_tool,
  200. "gg_duration_total": gg_duration,
  201. "voice": voice
  202. }
  203. processed_list.append(json.dumps(number_dict, ensure_ascii=False))
  204. if channel_id == "抖音" or channel_id == "快手" or channel_id == "视频号":
  205. if ls_number and ls_number not in {'None', ''}:
  206. if channel_id == "抖音":
  207. new_channel_id = "抖音历史"
  208. if channel_id == "快手":
  209. new_channel_id = "快手历史"
  210. if channel_id == "视频号":
  211. new_channel_id = "视频号历史"
  212. values1 = [new_channel_id, video_id_total, piaoquan_id, video_share, video_ending_total, crop_tool,
  213. gg_duration, title_total]
  214. filtered_values1 = [str(value) for value in values1 if value is not None and value != "None"]
  215. task_mark1 = "_".join(map(str, filtered_values1))
  216. number_dict = {
  217. "task_mark": task_mark1,
  218. "channel_id": new_channel_id,
  219. "channel_url": user,
  220. "piaoquan_id": piaoquan_id,
  221. "number": ls_number,
  222. "title": title,
  223. "video_share": video_share,
  224. "video_ending": video_ending,
  225. "crop_total": crop_tool,
  226. "gg_duration_total": gg_duration,
  227. "voice": voice
  228. }
  229. processed_list.append(json.dumps(number_dict, ensure_ascii=False))
  230. else:
  231. return processed_list
  232. return processed_list
  233. except:
  234. return processed_list
  235. """
  236. 获取对应片尾+srt
  237. """
  238. @classmethod
  239. def get_pwsrt_data(cls, feishu_id, feishu_sheet, video_ending):
  240. data = Feishu.get_values_batch(feishu_id, feishu_sheet)
  241. for row in data[1:]:
  242. pw_mark = row[0]
  243. pw_id = row[1]
  244. pw_srt = row[2]
  245. if pw_id != 'None' and pw_id != '' and pw_id != None:
  246. if pw_mark == video_ending:
  247. number = {"pw_id": pw_id, "pw_srt": pw_srt}
  248. return number
  249. return ''
  250. """
  251. 获取对应固定字幕
  252. """
  253. @classmethod
  254. def get_pzsrt_data(cls, feishu_id, feishu_sheet, video_share_name):
  255. data = Feishu.get_values_batch(feishu_id, feishu_sheet)
  256. for row in data[1:]:
  257. pz_mark = row[0]
  258. pz_zm = row[1]
  259. if pz_zm != 'None' and pz_zm != '' and pz_zm != None:
  260. if pz_mark == video_share_name:
  261. return pz_zm
  262. return ''
  263. """
  264. 获取 cookie 信息
  265. """
  266. @classmethod
  267. def get_cookie_data(cls, feishu_id, cookie_sheet, channel):
  268. data = Feishu.get_values_batch(feishu_id, cookie_sheet)
  269. for row in data[1:]:
  270. channel_mask = row[0]
  271. cookie = row[1]
  272. if channel_mask == channel:
  273. return cookie