# download_zillow_data.R (week9)
#
# Run this once per semester (and again whenever you want fresher data),
# from this same folder. Creates a local "zdata" folder with the
# county-level Zillow CSVs zillow-map.qmd and save_zillow_county_data.R
# expect to find there.
#
# As of 2026-10-12, Zillow's research data page
# (https://www.zillow.com/research/data/) lists County as an available
# geography for ZHVI and ZORI but doesn't expose a direct County-level
# download link on that page itself -- both URLs below are left as TODO
# until you track down the real ones.

dir.create("zdata", showWarnings = FALSE)

urls <- c(
  "TODO: paste current County-level ZHVI URL here",
  "TODO: paste current County-level ZORI URL here"
)

for (url in urls) {
  if (startsWith(url, "TODO")) {
    warning("Skipping a TODO URL -- update download_zillow_data.R first: ", url)
    next
  }
  dest <- file.path("zdata", basename(url))
  download.file(url, destfile = dest, mode = "wb", quiet = TRUE)
  message("Downloaded ", basename(dest))
}

writeLines(
  paste("zdata downloaded:", Sys.Date()),
  file.path("zdata", "README_last_updated.txt")
)
