fix: fetcher 数据库路径可移植化(db.py get_conn 统一,去除 Windows 硬编码)

This commit is contained in:
lookt
2026-09-15 21:25:23 +08:00
parent d03b4c0089
commit dee0e798f3
6 changed files with 46 additions and 9 deletions
+4 -2
View File
@@ -1,13 +1,15 @@
"""A股新闻采集 - AkShare stock_news_em"""
import warnings, logging, sqlite3
from datetime import datetime
from pathlib import Path
import pandas as pd
from src.storage.db import get_conn
import akshare as ak
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')
log = logging.getLogger(__name__)
DB = r'C:\Users\lookt\a_stock_timeline\data\a_stock.db'
DB = str(Path(__file__).resolve().parent.parent.parent / 'data' / 'a_stock.db')
def fetch_news():
df = ak.stock_news_em(symbol='A股')
@@ -32,7 +34,7 @@ def fetch_news():
df['inserted_at'] = datetime.now().isoformat()
if 'id' not in df.columns:
df.insert(0, 'id', range(1, len(df) + 1))
conn = sqlite3.connect(DB)
conn = get_conn()
df.to_sql('news_cn', conn, if_exists='replace', index=False)
conn.close()
log.info(f'写入 news_cn: {len(df)}')