Files
lianghua/export_all.py
T

31 lines
777 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""全库导出为 xlsx(每个表一个 sheet"""
import sqlite3
import pandas as pd
from pathlib import Path
from datetime import datetime
DB = r'C:\Users\lookt\a_stock_timeline\data\a_stock.db'
OUT = r'C:\Users\lookt\a_stock_timeline\data\a_stock_all.xlsx'
TABLES = [
'trade_calendar',
'stock_daily',
'lhb_daily',
'news_flash',
'macro_event',
'news_cn',
'money_flow',
'global_index',
]
conn = sqlite3.connect(DB)
with pd.ExcelWriter(OUT, engine='openpyxl', datetime_format='YYYY-MM-DD') as writer:
for tbl in TABLES:
df = pd.read_sql(f'SELECT * FROM {tbl}', conn)
print(f'{tbl}: {len(df)} 行 -> sheet')
df.to_excel(writer, sheet_name=tbl, index=False)
conn.close()
print(f'\n[OK] 导出完成: {OUT}')