41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from . import app, api_response
|
|
|
|
import time
|
|
|
|
from lib import chat_session, db_manager
|
|
|
|
|
|
@app.route('/api/db/datetime')
|
|
def db_status():
|
|
return api_response(success=True, data={'message': chat_session.status()})
|
|
|
|
|
|
@app.route('/api/db/update')
|
|
def db_update():
|
|
current_time = time.localtime(time.time() - 24 * 60 * 60)
|
|
day = current_time.tm_mday
|
|
month = current_time.tm_mon
|
|
year = current_time.tm_year
|
|
if chat_session.status() == f"{year}-{month:02d}-{day:02d}-23":
|
|
return api_response(success=False, error="数据库已更新", status_code=201)
|
|
for hour in range(24):
|
|
chat_session.process_chat_session(year, month, day, hour)
|
|
start = f"{year}-{month:02d}-{day:02d} 00:00:00"
|
|
end = f"{year}-{month:02d}-{day:02d} 23:59:59"
|
|
|
|
chat_session.update_qa_data(start, end)
|
|
db_manager.upload_db()
|
|
return api_response(success=True, data={'message': '数据库更新成功'})
|
|
|
|
|
|
@app.route('/api/db/upload')
|
|
def db_upload():
|
|
db_manager.upload_db()
|
|
return api_response(success=True, data={'message': '数据库上传成功'})
|
|
|
|
|
|
@app.route('/api/db/download')
|
|
def db_download():
|
|
db_manager.download_db()
|
|
return api_response(success=True, data={'message': '数据库下载成功'})
|