-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathinit_database.py
More file actions
74 lines (59 loc) · 2.32 KB
/
Copy pathinit_database.py
File metadata and controls
74 lines (59 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""
Database Initialization Script - One-click initialization and data import
"""
import os
import sys
from breadfree.data.database import DatabaseManager
from breadfree.data.data_importer import DataImporter
def main():
"""Main initialization function"""
print("=" * 50)
print("BreadFree Database Initialization Tool")
print("=" * 50)
# Check dependency files
csv_path = "breadfree/data/cache/top_150_with_sectors.csv"
cache_dir = "breadfree/data/cache"
if not os.path.exists(csv_path):
print(f"❌ Stock info file not found: {csv_path}")
sys.exit(1)
if not os.path.exists(cache_dir):
print(f"❌ Cache directory not found: {cache_dir}")
sys.exit(1)
print("✅ Dependency check passed")
# Create database manager
print("\nCreating database...")
db_manager = DatabaseManager(is_del=True) # is_del=True
# Create data importer
importer = DataImporter(db_manager)
# Initialize stock information
print("\nInitializing stock information from CSV...")
db_manager.init_from_csv(csv_path)
print("✅ Stock info initialization complete")
# Import cache data
print("\nImporting cached data into database...")
importer.import_cache_data()
print("✅ Data import complete")
# Show final status
status = importer.get_import_status()
print("\n" + "=" * 50)
print("🎉 Database initialization complete!")
print("=" * 50)
print(f"📊 Stock count: {status['stock_count']}")
print(f"📈 Daily records: {status['daily_records']}")
print(f"📅 Monthly records: {status['monthly_records']}")
print(f"📊 Technical indicators: {status['indicator_records']}")
print(f"🕒 Update time: {status['last_update']}")
print("\nDatabase file: breadfree.db")
print("=" * 50)
# Get stock list
stocks = db_manager.get_stock_list()
print(f"Number of stocks: {len(stocks)}")
# Get daily data for a specific stock
data = db_manager.get_daily_data('601288', start_date='2024-01-01', end_date='2024-12-31')
print(f"Daily records for 601288: {len(data)}")
# Get technical indicators
indicators = db_manager.get_technical_indicators('601288', start_date='2024-01-01')
print(f"Indicator records for 601288: {len(indicators)}")
if __name__ == "__main__":
main()