import redivis
import os
CORELOGIC_DATA_PATH = os.environ.get("CORELOGIC_DATA_PATH", None)
if CORELOGIC_DATA_PATH is None:
    raise ValueError("CORELOGIC_DATA_PATH is not set")

user = redivis.user("sul")
dataset = user.dataset("corelogic_loan_level_market_analytics:rt7m:v3_0")
table = dataset.table("performance:jxzj")
#print(dir(table))
# Export to a local CSV file
#print(help(table.download))
table.download(
    path=os.path.join(CORELOGIC_DATA_PATH, "performance_data1.csv"),  # Path to save the file
    format="csv",  # File format
    overwrite=True,  # Overwrite if file already exists
    progress=True  # Show progress bar
)
print("Downloaded data to performance_data.csv")