-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_sqlite.py
More file actions
32 lines (26 loc) · 1.01 KB
/
Copy pathexport_sqlite.py
File metadata and controls
32 lines (26 loc) · 1.01 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
"""Export SQLite data to JSON for import into PostgreSQL."""
import sqlite3
import json
from datetime import datetime
conn = sqlite3.connect('instance/financial_analysis.db')
conn.row_factory = sqlite3.Row
tables_to_export = [
'users', 'watchlist', 'alerts', 'portfolio_accounts', 'portfolio',
'transactions', 'options_positions', 'dividends', 'user_sessions',
'market_conditions', 'portfolio_snapshots', 'alert_suggestions',
'discussion_threads', 'thread_replies', 'thread_votes', 'copy_trading_follows',
]
export = {}
for table in tables_to_export:
try:
cursor = conn.execute(f'SELECT * FROM "{table}"')
rows = [dict(row) for row in cursor.fetchall()]
if rows:
export[table] = rows
print(f" {table}: {len(rows)} rows")
except Exception as e:
pass # Table doesn't exist in SQLite
conn.close()
with open('sqlite_export.json', 'w') as f:
json.dump(export, f, default=str, indent=2)
print(f"\nExported to sqlite_export.json ({len(export)} tables)")