BUG修正
This commit is contained in:
parent
6239d521dd
commit
77d81ffa4b
@ -1,4 +1,4 @@
|
|||||||
from fastapi import APIRouter, Depends, Query
|
from fastapi import APIRouter, Depends, Query, HTTPException, UploadFile, File
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from datetime import date
|
from datetime import date
|
||||||
@ -6,6 +6,7 @@ from app.core.database import get_db
|
|||||||
from app.services.lottery import LotteryService
|
from app.services.lottery import LotteryService
|
||||||
from app.schemas.lottery import SSQLottery, DLTLottery, LotteryQuery
|
from app.schemas.lottery import SSQLottery, DLTLottery, LotteryQuery
|
||||||
import random
|
import random
|
||||||
|
import tempfile
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@ -110,3 +111,21 @@ def generate_dlt_numbers(strategy: str = Query("random"), count: int = Query(1))
|
|||||||
"back_balls": back_balls
|
"back_balls": back_balls
|
||||||
})
|
})
|
||||||
return {"results": results}
|
return {"results": results}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/ssq/import")
|
||||||
|
def import_ssq_data(file: UploadFile = File(...), db: Session = Depends(get_db)):
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
||||||
|
tmp.write(file.file.read())
|
||||||
|
tmp_path = tmp.name
|
||||||
|
count = LotteryService.import_ssq_data(db, tmp_path)
|
||||||
|
return {"imported": count}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/dlt/import")
|
||||||
|
def import_dlt_data(file: UploadFile = File(...), db: Session = Depends(get_db)):
|
||||||
|
with tempfile.NamedTemporaryFile(delete=False) as tmp:
|
||||||
|
tmp.write(file.file.read())
|
||||||
|
tmp_path = tmp.name
|
||||||
|
count = LotteryService.import_dlt_data(db, tmp_path)
|
||||||
|
return {"imported": count}
|
||||||
|
|||||||
@ -173,6 +173,8 @@ class LotteryService:
|
|||||||
# pandas 端彻底去重
|
# pandas 端彻底去重
|
||||||
new_rows = df[~df['issue'].astype(str).isin(
|
new_rows = df[~df['issue'].astype(str).isin(
|
||||||
existing_issues)].drop_duplicates(subset=['issue'])
|
existing_issues)].drop_duplicates(subset=['issue'])
|
||||||
|
# 按open_time升序排序
|
||||||
|
new_rows = new_rows.sort_values(by='open_time', ascending=True)
|
||||||
|
|
||||||
objs = [
|
objs = [
|
||||||
SSQLottery(
|
SSQLottery(
|
||||||
@ -210,6 +212,8 @@ class LotteryService:
|
|||||||
# pandas 端彻底去重
|
# pandas 端彻底去重
|
||||||
new_rows = df[~df['issue'].astype(str).isin(
|
new_rows = df[~df['issue'].astype(str).isin(
|
||||||
existing_issues)].drop_duplicates(subset=['issue'])
|
existing_issues)].drop_duplicates(subset=['issue'])
|
||||||
|
# 按open_time升序排序
|
||||||
|
new_rows = new_rows.sort_values(by='open_time', ascending=True)
|
||||||
|
|
||||||
objs = [
|
objs = [
|
||||||
DLTLottery(
|
DLTLottery(
|
||||||
@ -237,9 +241,9 @@ class LotteryService:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_latest_ssq(db: Session) -> Optional[SSQLottery]:
|
def get_latest_ssq(db: Session) -> Optional[SSQLottery]:
|
||||||
"""获取最新一期双色球开奖记录"""
|
"""获取最新一期双色球开奖记录"""
|
||||||
return db.query(SSQLottery).order_by(desc(SSQLottery.issue)).first()
|
return db.query(SSQLottery).order_by(desc(SSQLottery.open_time)).first()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_latest_dlt(db: Session) -> Optional[DLTLottery]:
|
def get_latest_dlt(db: Session) -> Optional[DLTLottery]:
|
||||||
"""获取最新一期大乐透开奖记录"""
|
"""获取最新一期大乐透开奖记录"""
|
||||||
return db.query(DLTLottery).order_by(desc(DLTLottery.issue)).first()
|
return db.query(DLTLottery).order_by(desc(DLTLottery.open_time)).first()
|
||||||
|
|||||||
@ -10,4 +10,6 @@ pymysql==1.1.0
|
|||||||
cryptography==41.0.5
|
cryptography==41.0.5
|
||||||
python-dotenv==1.0.0
|
python-dotenv==1.0.0
|
||||||
pandas==2.1.3
|
pandas==2.1.3
|
||||||
aiofiles==23.2.1
|
aiofiles==23.2.1
|
||||||
|
requests==2.31.0
|
||||||
|
schedule==1.2.1
|
||||||
39
backend/schedule_update.py
Normal file
39
backend/schedule_update.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import schedule
|
||||||
|
import time
|
||||||
|
from update_lottery import LotteryUpdater
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# 配置日志
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||||
|
filename='lottery_update.log'
|
||||||
|
)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def update_job():
|
||||||
|
"""定时更新任务"""
|
||||||
|
try:
|
||||||
|
logger.info("开始执行定时更新任务...")
|
||||||
|
updater = LotteryUpdater()
|
||||||
|
updater.update_all_lottery_data()
|
||||||
|
logger.info("定时更新任务完成")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"定时更新任务失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# 设置定时任务
|
||||||
|
# 每天凌晨2点执行更新
|
||||||
|
schedule.every().day.at("02:00").do(update_job)
|
||||||
|
|
||||||
|
logger.info("定时更新服务已启动")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
schedule.run_pending()
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@ -336,6 +336,7 @@ const handleCurrentChange = (val) => {
|
|||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
// 然后获取完整列表
|
||||||
fetchData()
|
fetchData()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user