123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- # -*- coding: utf-8 -*-
- # @Time: 2023/12/26
- import os
- import random
- import sys
- import datetime
- sys.path.append(os.getcwd())
- from datetime import datetime, timedelta
- from common.db import MysqlHelper
- from common.feishu import Feishu
- class Material():
- # 获取所有用户名
- @classmethod
- def feishu_name(cls):
- summary = Feishu.get_values_batch("summary", "n9xlLF")
- list = []
- for row in summary[2:]:
- mark = row[0]
- mark_name = row[1]
- list.append({"mark": mark, "mark_name": mark_name})
- return list
- # 获取汇总表所有
- @classmethod
- def feishu_list(cls):
- summary = Feishu.get_values_batch("summary", "n9xlLF")
- list = []
- for row in summary[2:]:
- mark = row[0]
- feishu_id = row[3]
- video_call = row[4]
- pq_id = row[7]
- number = {"mark": mark, "feishu_id": feishu_id, "video_call": video_call, "pq_id": pq_id}
- list.append(number)
- return list
- # 获取管理后台cookie
- @classmethod
- def get_houtai_cookie(cls):
- douyin_token = Feishu.get_values_batch("MW7VsTb1vhctEot34g7ckrjdnIe", "pLWwBm")
- for item in douyin_token:
- if item[0] == '管理后台':
- return item[1]
- # 获取汇总表所有待抓取 用户
- @classmethod
- def get_all_user(cls, type):
- summary = Feishu.get_values_batch("summary", "n9xlLF")
- list = []
- for row in summary[2:]:
- mark = row[0]
- feishu_id = row[3]
- sheet = row[5]
- token = row[6]
- parts = sheet.split(',')
- result = []
- for part in parts:
- sub_parts = part.split('--')
- result.append(sub_parts)
- douyin = result[0]
- kuanshou = result[1]
- if type == "douyin":
- number = {"mark": mark, "feishu_id": feishu_id, "channel": douyin, "token": token}
- list.append(number)
- elif type == "kuaishou":
- number = {"mark": mark, "feishu_id": feishu_id, "channel": kuanshou, "token": token}
- list.append(number)
- return list
- # 获取抖音 cookie
- @classmethod
- def get_cookie(cls, feishu_id, token, channel):
- token = Feishu.get_values_batch(feishu_id, token)
- for item in token:
- if item[0] == channel:
- return item[1]
- # 获取抖音视频链接 存入数据库
- @classmethod
- def insert_user(cls, feishu_id, channel_id, mark, channel):
- # 获取抖音视频链接
- douyin = Feishu.get_values_batch(feishu_id, channel_id)
- # 提取账号昵称和账号主页链接
- for row in douyin[1:]:
- uid = row[1]
- insert_sql = f"""INSERT INTO agc_channel_data (user_id, channel, mark) values ('{uid}', '{channel}', '{mark}')"""
- MysqlHelper.update_values(
- sql=insert_sql,
- env="prod",
- machine="",
- )
- @classmethod
- def get_uid(cls, uid, mark):
- current_time = datetime.now()
- formatted_time = current_time.strftime("%Y-%m-%d")
- uid_list = f"""select account_id FROM agc_video_deposit where time = '{formatted_time}' AND audio = '{uid}' and mark = '{mark}' GROUP BY account_id """
- id_list = MysqlHelper.get_values(uid_list, "prod")
- return id_list
- # 获取音频类型+字幕+标题
- @classmethod
- def get_all_data(cls, feishu_id, link, mark):
- list = []
- title_list = []
- # 获取音频类型+字幕+标题
- all_data = Feishu.get_values_batch(feishu_id, link)
- for row in all_data[1:]:
- uid = row[1]
- text = row[2]
- title = row[3]
- number = {"uid": uid, "text": text}
- if uid:
- list.append(number)
- title_list.append(title)
- while True:
- list1 = random.choice(list)
- uid1 = list1['uid']
- srt = list1['text']
- id_list = cls.get_uid(uid1, mark)
- if len(id_list) < 1:
- return uid1, srt, title_list
|