material.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. audio_id = list['audio_id']
  48. srt = list['text']
  49. return audio_id, srt
  50. # 获取抖音 cookie
  51. @classmethod
  52. def get_douyin_cookie(cls):
  53. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  54. for item in douyin_token:
  55. if item[0] == '抖音':
  56. return item[1]
  57. @classmethod
  58. def get_houtai_cookie(cls):
  59. douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
  60. for item in douyin_token:
  61. if item[0] == '管理后台':
  62. return item[1]