Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os

class StockAnalysisDatabase:
def __init__(self, db_path="stock_analysis.db"):
def __init__(self, db_path="data/stock_analysis.db"):
"""初始化数据库连接"""
self.db_path = db_path
# 确保数据库所在目录存在
Expand Down Expand Up @@ -158,4 +158,4 @@ def get_record_count(self):
return count

# 全局数据库实例
db = StockAnalysisDatabase()
db = StockAnalysisDatabase()
8 changes: 6 additions & 2 deletions longhubang_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
from datetime import datetime
import json
import pandas as pd
import os


class LonghubangDatabase:
"""龙虎榜数据库管理类"""

def __init__(self, db_path='longhubang.db'):
def __init__(self, db_path='data/longhubang.db'):
"""
初始化数据库

Args:
db_path: 数据库文件路径
"""
self.db_path = db_path
# 确保数据库所在目录存在
db_dir = os.path.dirname(self.db_path)
if db_dir and not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)
self.init_database()

def get_connection(self):
Expand Down Expand Up @@ -495,4 +500,3 @@ def get_statistics(self):
# 获取统计信息
stats = db.get_statistics()
print(f"\n数据库统计: {stats}")

4 changes: 2 additions & 2 deletions monitor_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class StockMonitorDatabase:
"""股票监测数据库管理类"""

def __init__(self, db_path: str = "stock_monitor.db"):
def __init__(self, db_path: str = "data/stock_monitor.db"):
self.db_path = db_path
# 确保数据库所在目录存在
db_dir = os.path.dirname(self.db_path)
Expand Down Expand Up @@ -523,4 +523,4 @@ def batch_add_or_update_monitors(self, monitors_data: List[Dict]) -> Dict[str, i
return result

# 全局数据库实例
monitor_db = StockMonitorDatabase()
monitor_db = StockMonitorDatabase()
8 changes: 6 additions & 2 deletions portfolio_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os

# 数据库文件路径
DB_PATH = "portfolio_stocks.db"
DB_PATH = "data/portfolio_stocks.db"


class PortfolioDB:
Expand All @@ -34,6 +34,11 @@ def _get_connection(self) -> sqlite3.Connection:

def _init_database(self):
"""初始化数据库表结构"""
# 确保数据库所在目录存在
db_dir = os.path.dirname(self.db_path)
if db_dir and not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)

conn = self._get_connection()
cursor = conn.cursor()

Expand Down Expand Up @@ -622,4 +627,3 @@ def get_all_latest_analysis(self) -> List[Dict]:
print(f" {h['analysis_time']}: {h['rating']} (信心度: {h['confidence']})")

print("\n[OK] 数据库测试完成")