feishu_form.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # -*- coding: utf-8 -*-
  2. import json
  3. import os
  4. import random
  5. import sys
  6. import datetime
  7. sys.path.append(os.getcwd())
  8. from common.feishu_utils import Feishu
  9. class Material():
  10. """
  11. 获取汇总表所有负责人列表
  12. """
  13. @classmethod
  14. def feishu_list(cls):
  15. summary = Feishu.get_values_batch("summary", "bc154d")
  16. list = []
  17. for row in summary[1:]:
  18. mark = row[0]
  19. name = row[1]
  20. feishu_id = row[3]
  21. feishu_sheet = row[4]
  22. cookie_sheet = row[5]
  23. number = {"mark": mark, "name": name, "feishu_id": feishu_id, "feishu_sheet": feishu_sheet, "cookie_sheet": cookie_sheet}
  24. if mark:
  25. list.append(number)
  26. else:
  27. return list
  28. return list
  29. """
  30. 获取对应负责人任务明细
  31. """
  32. @classmethod
  33. def get_task_data(cls, feishu_id, feishu_sheet):
  34. data = Feishu.get_values_batch(feishu_id, feishu_sheet)
  35. processed_list = []
  36. try:
  37. for row in data[1:]:
  38. channel_id = row[1]
  39. channel_url = row[2]
  40. piaoquan_id = row[3]
  41. number = row[4]
  42. video_share = row[5]
  43. video_ending = row[6]
  44. crop_tool = row[7]
  45. gg_duration = row[8]
  46. title = row[9]
  47. try:
  48. ls_number = int(row[10])
  49. except:
  50. ls_number = None
  51. def count_items(item, separator):
  52. if item and item not in {'None', ''}:
  53. return len(item.split(separator))
  54. return 0
  55. video_id_total = count_items(str(channel_url), ',')
  56. title_total = count_items(str(title), '/')
  57. video_ending_total = count_items(str(video_ending), ',')
  58. values = [channel_id, video_id_total, piaoquan_id, video_share, video_ending_total, crop_tool, gg_duration, title_total]
  59. filtered_values = [str(value) for value in values if value is not None and value != "None"]
  60. task_mark = "_".join(map(str, filtered_values))
  61. if piaoquan_id and piaoquan_id not in {'None', ''}:
  62. if ',' in channel_url:
  63. channel_url = channel_url.split(',')
  64. else:
  65. channel_url = [channel_url]
  66. for user in channel_url:
  67. number_dict = {
  68. "task_mark": task_mark,
  69. "channel_id": channel_id,
  70. "channel_url": user,
  71. "piaoquan_id": piaoquan_id,
  72. "number": number,
  73. "title": title,
  74. "video_share": video_share,
  75. "video_ending": video_ending,
  76. "crop_total": crop_tool,
  77. "gg_duration_total": gg_duration,
  78. }
  79. processed_list.append(json.dumps(number_dict, ensure_ascii=False))
  80. if ls_number and ls_number not in {'None', ''}:
  81. if channel_id == "抖音":
  82. new_channel_id = "抖音历史"
  83. if channel_id == "快手":
  84. new_channel_id = "快手历史"
  85. values = [new_channel_id, video_id_total, piaoquan_id, video_share, video_ending_total, crop_tool,
  86. gg_duration, title_total]
  87. filtered_values = [str(value) for value in values if value is not None and value != "None"]
  88. task_mark = "_".join(map(str, filtered_values))
  89. number_dict = {
  90. "task_mark": task_mark,
  91. "channel_id": new_channel_id,
  92. "channel_url": user,
  93. "piaoquan_id": piaoquan_id,
  94. "number": ls_number,
  95. "title": title,
  96. "video_share": video_share,
  97. "video_ending": video_ending,
  98. "crop_total": crop_tool,
  99. "gg_duration_total": gg_duration,
  100. }
  101. processed_list.append(json.dumps(number_dict, ensure_ascii=False))
  102. else:
  103. return processed_list
  104. return processed_list
  105. except:
  106. return processed_list
  107. """
  108. 获取对应片尾+srt
  109. """
  110. @classmethod
  111. def get_pwsrt_data(cls, feishu_id, feishu_sheet, video_ending):
  112. data = Feishu.get_values_batch(feishu_id, feishu_sheet)
  113. for row in data[1:]:
  114. pw_mark = row[0]
  115. pw_id = row[1]
  116. pw_srt = row[2]
  117. if pw_id != 'None' and pw_id != '' and pw_id != None:
  118. if pw_mark == video_ending:
  119. number = {"pw_id": pw_id, "pw_srt": pw_srt}
  120. return number
  121. return ''
  122. """
  123. 获取对应固定字幕
  124. """
  125. @classmethod
  126. def get_pzsrt_data(cls, feishu_id, feishu_sheet, video_share_name):
  127. data = Feishu.get_values_batch(feishu_id, feishu_sheet)
  128. for row in data[1:]:
  129. pz_mark = row[0]
  130. pz_zm = row[1]
  131. if pz_zm != 'None' and pz_zm != '' and pz_zm != None:
  132. if pz_mark == video_share_name:
  133. return pz_zm
  134. return ''
  135. """
  136. 获取 cookie 信息
  137. """
  138. @classmethod
  139. def get_cookie_data(cls, feishu_id, cookie_sheet, channel):
  140. data = Feishu.get_values_batch(feishu_id, cookie_sheet)
  141. for row in data[1:]:
  142. channel_mask = row[0]
  143. cookie = row[1]
  144. if channel_mask == channel:
  145. return cookie