You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.6 KiB
71 lines
1.6 KiB
# coding=utf-8
|
|
from dataclasses import dataclass, field
|
|
import os
|
|
import config
|
|
import utils
|
|
from datetime import datetime
|
|
|
|
@dataclass
|
|
class AiSearchResult:
|
|
|
|
"""
|
|
ai搜索结果对象
|
|
"""
|
|
|
|
# 标题
|
|
title: str = ''
|
|
# url
|
|
url: str = ''
|
|
# 来源
|
|
host_name: str = ''
|
|
# 描述
|
|
body: str = ''
|
|
# 发布时间
|
|
publish_time: str|int|float|datetime = ''
|
|
#是否被ai引用
|
|
is_referenced: str = '0'
|
|
#情感倾向" 1- 中立 2- 正面 3- 负面
|
|
sentiment_type = 0
|
|
#情感类型
|
|
type = 0
|
|
def __post_init__(self):
|
|
|
|
if isinstance(self.publish_time, datetime):
|
|
self.publish_time = self.publish_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
if isinstance(self.publish_time, float):
|
|
self.publish_time = int(self.publish_time)
|
|
|
|
if isinstance(self.publish_time, int):
|
|
self.publish_time = utils.convert_timestamp(self.publish_time).strftime('%Y-%m-%d')
|
|
|
|
if isinstance(self.publish_time, str):
|
|
try:
|
|
now = datetime.now()
|
|
publish = datetime.strptime(self.publish_time, f'%m-%d')
|
|
except ValueError:
|
|
return
|
|
self.publish_time = publish.strftime(f'{now.year}-%m-%d')
|
|
|
|
|
|
@dataclass
|
|
class AiAnswer:
|
|
"""
|
|
ai回答对象
|
|
"""
|
|
|
|
platform_id: int
|
|
platform_name: str
|
|
prompt: str
|
|
keyword: str
|
|
answer: str = ''
|
|
search_result: list[AiSearchResult] = field(default_factory=list)
|
|
screenshot_file: str = ''
|
|
# 状态
|
|
run_status: bool = True
|
|
|
|
def __post_init__(self):
|
|
self.screenshot_file = os.path.abspath(self.screenshot_file)
|
|
|
|
|
|
|