From c283a1d85e6ecd18aa1045fa17089c492b20038a Mon Sep 17 00:00:00 2001 From: "Adam H. Sparks" Date: Sat, 2 Nov 2024 21:30:16 +0800 Subject: [PATCH] use httr2 to download files with retries --- DESCRIPTION | 1 + R/get_historical_forecast_database.R | 14 +++++++----- codemeta.json | 32 +++++++++++++++++++--------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ad50ba7..3d5905c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,6 +18,7 @@ Imports: cli, curl, data.table, + httr2, lubridate, openxlsx2, purrr, diff --git a/R/get_historical_forecast_database.R b/R/get_historical_forecast_database.R index 66ff3d4..81a08e6 100644 --- a/R/get_historical_forecast_database.R +++ b/R/get_historical_forecast_database.R @@ -40,11 +40,15 @@ #' get_historical_forecast() #' get_historical_forecast_database <- function() { - f <- file.path(tempdir(), "historical_db") - curl::curl_download( - url = "https://daff.ent.sirsidynix.net.au/client/en_AU/search/asset/1031941/0", - destfile = f, - handle = create_handle()) + f <- file.path(tempdir(), "historical_db.xlsx") + response <- + httr2::request( + base_url = "https://daff.ent.sirsidynix.net.au/client/en_AU/search/asset/1031941/0") |> + httr2::req_retry(max_tries = 5) |> + httr2::req_perform() + + writeBin(response$body, con = f) + x <- data.table::as.data.table(openxlsx2::read_xlsx(f, sheet = "Database", na.strings = "na")) diff --git a/codemeta.json b/codemeta.json index 1c574c2..082f234 100644 --- a/codemeta.json +++ b/codemeta.json @@ -146,6 +146,18 @@ "sameAs": "https://CRAN.R-project.org/package=data.table" }, "4": { + "@type": "SoftwareApplication", + "identifier": "httr2", + "name": "httr2", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=httr2" + }, + "5": { "@type": "SoftwareApplication", "identifier": "lubridate", "name": "lubridate", @@ -157,7 +169,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=lubridate" }, - "5": { + "6": { "@type": "SoftwareApplication", "identifier": "openxlsx2", "name": "openxlsx2", @@ -169,7 +181,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=openxlsx2" }, - "6": { + "7": { "@type": "SoftwareApplication", "identifier": "purrr", "name": "purrr", @@ -181,7 +193,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=purrr" }, - "7": { + "8": { "@type": "SoftwareApplication", "identifier": "readtext", "name": "readtext", @@ -193,7 +205,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=readtext" }, - "8": { + "9": { "@type": "SoftwareApplication", "identifier": "sf", "name": "sf", @@ -205,7 +217,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=sf" }, - "9": { + "10": { "@type": "SoftwareApplication", "identifier": "stars", "name": "stars", @@ -217,7 +229,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=stars" }, - "10": { + "11": { "@type": "SoftwareApplication", "identifier": "stringr", "name": "stringr", @@ -229,7 +241,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=stringr" }, - "11": { + "12": { "@type": "SoftwareApplication", "identifier": "terra", "name": "terra", @@ -241,7 +253,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=terra" }, - "12": { + "13": { "@type": "SoftwareApplication", "identifier": "tidync", "name": "tidync", @@ -253,7 +265,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=tidync" }, - "13": { + "14": { "@type": "SoftwareApplication", "identifier": "withr", "name": "withr", @@ -267,7 +279,7 @@ }, "SystemRequirements": null }, - "fileSize": "329.335KB", + "fileSize": "1628.623KB", "citation": [ { "@type": "SoftwareSourceCode",