From 77dbe8cc7fc3e2fc084e906af687074fa35cabe1 Mon Sep 17 00:00:00 2001 From: Rob Wiederstein Date: Mon, 9 Mar 2026 17:22:31 -0400 Subject: [PATCH] Consolidate weekly refresh into single orchestrator script refresh_all.R downloads both SCPA files once, then sources update_owners.R and update_sales.R. Single cron job at 11pm Sunday. --- data-raw/refresh_all.R | 35 +++++++++++++++++++++++++++++++++++ data-raw/update_owners.R | 7 ------- data-raw/update_sales.R | 12 ++---------- 3 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 data-raw/refresh_all.R diff --git a/data-raw/refresh_all.R b/data-raw/refresh_all.R new file mode 100644 index 0000000..06e830c --- /dev/null +++ b/data-raw/refresh_all.R @@ -0,0 +1,35 @@ +# refresh_all.R +# Weekly orchestrator. Downloads SCPA data files once, then updates +# owners and sales. Run via cron; container restart handled by cron. + +options(timeout = 300) + +cat("=== stAndrews weekly refresh", format(Sys.time()), "===\n") + +# ── Download SCPA Public.xlsx ───────────────────────────────────────────────── +cat("Downloading SCPA Public.xlsx...\n") +download.file( + url = "https://www.sc-pa.com/downloads/SCPA%20Public.xlsx", + destfile = "./data-raw/property/SCPA Public.xlsx", + mode = "wb" +) +cat("Done.\n") + +# ── Download SCPA_Parcels_Sales_CSV.zip ─────────────────────────────────────── +cat("Downloading SCPA_Parcels_Sales_CSV.zip...\n") +download.file( + url = "https://www.sc-pa.com/downloads/SCPA_Parcels_Sales_CSV.zip", + destfile = "./data-raw/property/SCPA_Parcels_Sales_CSV.zip", + mode = "wb" +) +cat("Done.\n") + +# ── Update owners ───────────────────────────────────────────────────────────── +cat("\n--- update_owners.R ---\n") +source("./data-raw/update_owners.R") + +# ── Update sales ────────────────────────────────────────────────────────────── +cat("\n--- update_sales.R ---\n") +source("./data-raw/update_sales.R") + +cat("\n=== Refresh complete", format(Sys.time()), "===\n") diff --git a/data-raw/update_owners.R b/data-raw/update_owners.R index 318f1be..5d8a473 100644 --- a/data-raw/update_owners.R +++ b/data-raw/update_owners.R @@ -22,13 +22,6 @@ subdivisions <- c( # load geometry lookup (static) ---- geometry_lookup <- readRDS("./data-raw/addresses/geometry_lookup.rds") -# download fresh scpa data ---- -download.file( - url = "https://www.sc-pa.com/downloads/SCPA%20Public.xlsx", - destfile = "./data-raw/property/SCPA Public.xlsx", - mode = "wb" -) - # load and clean scpa data ---- owners_raw <- readxl::read_xlsx( diff --git a/data-raw/update_sales.R b/data-raw/update_sales.R index 084c938..452ded8 100644 --- a/data-raw/update_sales.R +++ b/data-raw/update_sales.R @@ -17,16 +17,8 @@ subdivisions <- c( geometry_lookup <- readRDS("./data-raw/addresses/geometry_lookup.rds") -# ── Download and extract Sarasota.csv ───────────────────────────────────────── -zip_path <- "./data-raw/property/SCPA_Parcels_Sales_CSV.zip" -options(timeout = 300) -download.file( - url = "https://www.sc-pa.com/downloads/SCPA_Parcels_Sales_CSV.zip", - destfile = zip_path, - mode = "wb" -) - -csv_con <- unz(zip_path, "Parcel_Sales_CSV/Sarasota.csv") +# ── Load Sarasota.csv from cached zip ──────────────────────────────────────── +csv_con <- unz("./data-raw/property/SCPA_Parcels_Sales_CSV.zip", "Parcel_Sales_CSV/Sarasota.csv") # ── Load and filter ─────────────────────────────────────────────────────────── sales <-