material.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. # @Time: 2023/12/26
  3. import os
  4. import random
  5. import sys
  6. sys.path.append(os.getcwd())
  7. from common.db import MysqlHelper
  8. from common.feishu import Feishu
  9. class Material():
  10. # 获取视频链接 存入数据库
  11. @classmethod
  12. def insert_user(cls):
  13. # 获取抖音视频链接
  14. douyin = Feishu.get_values_batch("prod", "succinct", "iYbVis")
  15. # 提取账号昵称和账号主页链接
  16. channel = '抖音'
  17. for row in douyin[2:]:
  18. platform = row[0]
  19. if platform == channel:
  20. account_name = row[2]
  21. account_link = row[3]
  22. user_id = account_link.split("user/")[1]
  23. insert_sql = f"""INSERT INTO video_user_id (name, user_id, channel) values ('{account_name}', '{user_id}', '{channel}')"""
  24. MysqlHelper.update_values(
  25. sql=insert_sql,
  26. env="prod",
  27. machine="",
  28. )
  29. # 随机获取标题
  30. @classmethod
  31. def get_title(cls):
  32. title = Feishu.get_values_batch("prod", "succinct", "meGnsz")
  33. random_item = random.choice(title)
  34. cleaned_item = random_item[0].strip("[]'")
  35. return cleaned_item
  36. # 获取所有音频
  37. @classmethod
  38. def get_audio(cls):
  39. audio = Feishu.get_values_batch("prod", "succinct", "zucQUM")
  40. list = []
  41. for row in audio[1:]:
  42. account_name = row[0]
  43. text = row[2]
  44. number = {"audio_id": account_name,"text": text}
  45. list.append(number)
  46. list = random.choice(list)
  47. print("随机获取音频+字幕为:"+list)
  48. audio_id = list['audio_id']
  49. srt = list['text']
  50. return audio_id, srt
  51. # 获取抖音 cookie
  52. @classmethod
  53. def get_douyin_cookie(cls):
  54. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  55. for item in douyin_token:
  56. if item[0] == '抖音':
  57. return item[1]
  58. @classmethod
  59. def get_houtai_cookie(cls):
  60. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  61. for item in douyin_token:
  62. if item[0] == '管理后台':
  63. return item[1]