MFLF-Demo / src /database /export_data.py
suratan.boon
update/dashboard
0957e29
raw
history blame contribute delete
672 Bytes
import sqlite3
import pandas as pd
def export_all_tables_to_csv(db_path='hello_earth_data_2.db', output_dir='.'):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Get list of all tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = [row[0] for row in cursor.fetchall()]
# Export each table
for table in tables:
df = pd.read_sql_query(f"SELECT * FROM {table}", conn)
output_path = f"{output_dir}/{table}.csv"
df.to_csv(output_path, index=False)
print(f"✅ Exported {table} to {output_path}")
conn.close()
if __name__ == '__main__':
export_all_tables_to_csv()