material.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # -*- coding: utf-8 -*-
  2. # @Time: 2023/12/26
  3. import os
  4. import random
  5. import sys
  6. import datetime
  7. sys.path.append(os.getcwd())
  8. from datetime import datetime, timedelta
  9. from common.db import MysqlHelper
  10. from common.feishu import Feishu
  11. class Material():
  12. # 获取所有用户名
  13. @classmethod
  14. def feishu_name(cls):
  15. summary = Feishu.get_values_batch("summary", "n9xlLF")
  16. list = []
  17. for row in summary[2:]:
  18. mark = row[0]
  19. mark_name = row[1]
  20. list.append({"mark": mark, "mark_name": mark_name})
  21. return list
  22. # 获取汇总表所有
  23. @classmethod
  24. def feishu_list(cls):
  25. summary = Feishu.get_values_batch("summary", "n9xlLF")
  26. list = []
  27. for row in summary[2:]:
  28. mark = row[0]
  29. feishu_id = row[3]
  30. video_call = row[4]
  31. pq_id = row[7]
  32. number = {"mark": mark, "feishu_id": feishu_id, "video_call": video_call, "pq_id": pq_id}
  33. list.append(number)
  34. return list
  35. # 获取管理后台cookie
  36. @classmethod
  37. def get_houtai_cookie(cls):
  38. douyin_token = Feishu.get_values_batch("MW7VsTb1vhctEot34g7ckrjdnIe", "pLWwBm")
  39. for item in douyin_token:
  40. if item[0] == '管理后台':
  41. return item[1]
  42. # 获取汇总表所有待抓取 用户
  43. @classmethod
  44. def get_all_user(cls, type):
  45. summary = Feishu.get_values_batch("summary", "n9xlLF")
  46. list = []
  47. for row in summary[2:]:
  48. mark = row[0]
  49. feishu_id = row[3]
  50. sheet = row[5]
  51. token = row[6]
  52. parts = sheet.split(',')
  53. result = []
  54. for part in parts:
  55. sub_parts = part.split('--')
  56. result.append(sub_parts)
  57. douyin = result[0]
  58. kuaishou = result[1]
  59. if type == "douyin":
  60. number = {"mark": mark, "feishu_id": feishu_id, "channel": douyin, "token": token}
  61. list.append(number)
  62. elif type == "kuaishou":
  63. number = {"mark": mark, "feishu_id": feishu_id, "channel": kuaishou, "token": token}
  64. list.append(number)
  65. return list
  66. # 获取抖音 cookie
  67. @classmethod
  68. def get_cookie(cls, feishu_id, token, channel):
  69. token = Feishu.get_values_batch(feishu_id, token)
  70. for item in token:
  71. if item[0] == channel:
  72. return item[1]
  73. # 获取抖音视频链接 存入数据库
  74. @classmethod
  75. def insert_user(cls, feishu_id, channel_id, mark, channel):
  76. # 获取抖音视频链接
  77. douyin = Feishu.get_values_batch(feishu_id, channel_id)
  78. # 提取账号昵称和账号主页链接
  79. for row in douyin[1:]:
  80. uid = row[1]
  81. insert_sql = f"""INSERT INTO agc_channel_data (user_id, channel, mark) values ('{uid}', '{channel}', '{mark}')"""
  82. MysqlHelper.update_values(
  83. sql=insert_sql,
  84. env="prod",
  85. machine="",
  86. )
  87. @classmethod
  88. def get_uid(cls, uid, mark):
  89. current_time = datetime.now()
  90. formatted_time = current_time.strftime("%Y-%m-%d")
  91. uid_list = f"""select account_id FROM agc_video_deposit where time = '{formatted_time}' AND audio = '{uid}' and mark = '{mark}' GROUP BY account_id """
  92. id_list = MysqlHelper.get_values(uid_list, "prod")
  93. return id_list
  94. # 获取音频类型+字幕+标题
  95. @classmethod
  96. def get_all_data(cls, feishu_id, link, mark):
  97. list = []
  98. title_list = []
  99. # 获取音频类型+字幕+标题
  100. all_data = Feishu.get_values_batch(feishu_id, link)
  101. for row in all_data[1:]:
  102. uid = row[1]
  103. text = row[2]
  104. title = row[3]
  105. number = {"uid": uid, "text": text}
  106. if uid:
  107. list.append(number)
  108. title_list.append(title)
  109. while True:
  110. list1 = random.choice(list)
  111. uid1 = list1['uid']
  112. srt = list1['text']
  113. id_list = cls.get_uid(uid1, mark)
  114. if len(id_list) < 1:
  115. return uid1, srt, title_list