Download src/database/export_data.py from casedone/MFLF-Demo: direct link, hf CLI and curl.
- Browser
- Download file 672 Bytes
-
https://huggingface.co/spaces/casedone/MFLF-Demo/resolve/main/src/database/export_data.py
- Command line
-
hf download hf://spaces/casedone/MFLF-Demo/src/database/export_data.py
-
curl -L -o export_data.py https://huggingface.co/spaces/casedone/MFLF-Demo/resolve/main/src/database/export_data.py
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() | |