'commit'
This commit is contained in:
79
Model/DouYinModel.py
Normal file
79
Model/DouYinModel.py
Normal file
@@ -0,0 +1,79 @@
|
||||
from DbKit.Db import Db
|
||||
from datetime import datetime
|
||||
|
||||
class DouYinModel:
|
||||
def __init__(self, db: Db = None):
|
||||
self.db = db or Db()
|
||||
|
||||
async def init(self):
|
||||
await self.db.init_db()
|
||||
|
||||
async def update_status(self, id, status, error_msg=None):
|
||||
await self.db.init_db()
|
||||
params = {
|
||||
"id": id,
|
||||
"status": status,
|
||||
"error_msg": error_msg
|
||||
}
|
||||
return await self.db.execute_update("DouYin.updateStatus", params)
|
||||
|
||||
async def update_record(self, id, title, obs_url, transcript, status):
|
||||
await self.db.init_db()
|
||||
# Truncate title to 100 chars to fit DB schema
|
||||
if title and len(title) > 100:
|
||||
title = title[:100] + "..."
|
||||
|
||||
params = {
|
||||
"id": id,
|
||||
"title": title,
|
||||
"obs_url": obs_url,
|
||||
"transcript": transcript,
|
||||
"status": status
|
||||
}
|
||||
return await self.db.execute_update("DouYin.updateRecord", params)
|
||||
|
||||
async def insert_record(self, id, url, create_time=None):
|
||||
await self.db.init_db()
|
||||
if create_time is None:
|
||||
create_time = datetime.now()
|
||||
params = {
|
||||
"id": id,
|
||||
"url": url,
|
||||
"create_time": create_time
|
||||
}
|
||||
return await self.db.execute_update("DouYin.insertRecord", params)
|
||||
|
||||
async def get_records(self, limit=50):
|
||||
await self.db.init_db()
|
||||
params = {"limit": limit}
|
||||
records = await self.db.find("DouYin.getRecords", params)
|
||||
|
||||
# Manually handle datetime serialization
|
||||
for r in records:
|
||||
if 'create_time' in r and r['create_time']:
|
||||
r['create_time'] = r['create_time'].strftime("%Y-%m-%d %H:%M:%S")
|
||||
if 'update_time' in r and r['update_time']:
|
||||
r['update_time'] = r['update_time'].strftime("%Y-%m-%d %H:%M:%S")
|
||||
return records
|
||||
|
||||
async def delete_record(self, id):
|
||||
await self.db.init_db()
|
||||
params = {"id": id}
|
||||
return await self.db.execute_update("DouYin.deleteRecord", params)
|
||||
|
||||
async def get_transcripts(self, ids=None, limit=20):
|
||||
await self.db.init_db()
|
||||
if ids:
|
||||
params = {"ids": ids}
|
||||
return await self.db.find("DouYin.getTranscriptsByIds", params)
|
||||
else:
|
||||
params = {"limit": limit}
|
||||
return await self.db.find("DouYin.getLatestTranscripts", params)
|
||||
|
||||
async def get_interrupted_tasks(self, limit=20):
|
||||
await self.db.init_db()
|
||||
params = {"limit": limit}
|
||||
return await self.db.find("DouYin.getInterruptedTasks", params)
|
||||
|
||||
async def close(self):
|
||||
await self.db.shutdown()
|
||||
24
Model/HaiBaoModel.py
Normal file
24
Model/HaiBaoModel.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import logging
|
||||
from DbKit.Db import Db
|
||||
|
||||
logger = logging.getLogger("HaiBaoModel")
|
||||
|
||||
class HaiBaoModel:
|
||||
def __init__(self):
|
||||
self.db = Db()
|
||||
|
||||
async def insert_record(self, id, prompt, image_url, scheme_content, created_at):
|
||||
"""插入生成记录"""
|
||||
params = {
|
||||
"id": id,
|
||||
"prompt": prompt,
|
||||
"image_url": image_url,
|
||||
"scheme_content": scheme_content,
|
||||
"created_at": created_at
|
||||
}
|
||||
return await self.db.execute_update("HaiBao.insertHistory", params)
|
||||
|
||||
async def get_history(self, limit=50):
|
||||
"""获取历史记录"""
|
||||
params = {"limit": limit}
|
||||
return await self.db.find("HaiBao.getHistory", params)
|
||||
@@ -53,3 +53,32 @@ class PriceComparisonResponse(BaseModel):
|
||||
class PriceComparisonSummary(BaseModel):
|
||||
summary: str
|
||||
|
||||
|
||||
from DbKit.Db import Db
|
||||
|
||||
class YltAnalyticsModel:
|
||||
def __init__(self):
|
||||
self.db = Db()
|
||||
|
||||
async def get_operators_price_trends(self, days: int):
|
||||
return await self.db.find("YltAnalytics.getOperatorsPriceTrends", {"days": days})
|
||||
|
||||
async def list_ylt_stations(self, q: str = None):
|
||||
params = {}
|
||||
if q:
|
||||
params["q"] = True
|
||||
params["kw"] = f"%{q}%"
|
||||
return await self.db.find("YltAnalytics.listYltStations", params)
|
||||
|
||||
async def fetch_current_stations(self):
|
||||
return await self.db.find("YltAnalytics.fetchCurrentStations")
|
||||
|
||||
async def fetch_station_schedule_json(self, station_hash: str):
|
||||
rows = await self.db.find("YltAnalytics.fetchStationScheduleJson", {"h": station_hash})
|
||||
if not rows:
|
||||
return None
|
||||
return rows[0].get("schedule_json")
|
||||
|
||||
async def fetch_current_station_rows(self, operator: str):
|
||||
return await self.db.find("YltAnalytics.fetchCurrentStationRows", {"op": operator})
|
||||
|
||||
|
||||
BIN
Model/__pycache__/DouYinModel.cpython-310.pyc
Normal file
BIN
Model/__pycache__/DouYinModel.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Model/__pycache__/HaiBaoModel.cpython-310.pyc
Normal file
BIN
Model/__pycache__/HaiBaoModel.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user