File size: 672 Bytes
e773157 7226f4e e773157 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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()
|