import pandas as pd
import pymysql
import os

# Configure database connection
conn = pymysql.connect(host='localhost', user='ntuh', password='n122119493', db='adm15')

# Execute query and load into a pandas DataFrame
df = pd.read_sql_query("SELECT * FROM registry_pathologyreport", conn)

# Export DataFrame to an Excel file
# output_file = '/data/patho-2026.xlsx'
# df.to_excel(output_file, index=False)
output_file_parquet = '/data/patho-2026.parquet'
df.to_parquet(output_file_parquet, index=False, engine='pyarrow')
print(f"Data exported to {output_file_parquet}")
