Skip to content

Commit

Permalink
use httr2 to download files with retries
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks committed Nov 2, 2024
1 parent 0728487 commit c283a1d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Imports:
cli,
curl,
data.table,
httr2,
lubridate,
openxlsx2,
purrr,
Expand Down
14 changes: 9 additions & 5 deletions R/get_historical_forecast_database.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
32 changes: 22 additions & 10 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -157,7 +169,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=lubridate"
},
"5": {
"6": {
"@type": "SoftwareApplication",
"identifier": "openxlsx2",
"name": "openxlsx2",
Expand All @@ -169,7 +181,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=openxlsx2"
},
"6": {
"7": {
"@type": "SoftwareApplication",
"identifier": "purrr",
"name": "purrr",
Expand All @@ -181,7 +193,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=purrr"
},
"7": {
"8": {
"@type": "SoftwareApplication",
"identifier": "readtext",
"name": "readtext",
Expand All @@ -193,7 +205,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=readtext"
},
"8": {
"9": {
"@type": "SoftwareApplication",
"identifier": "sf",
"name": "sf",
Expand All @@ -205,7 +217,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=sf"
},
"9": {
"10": {
"@type": "SoftwareApplication",
"identifier": "stars",
"name": "stars",
Expand All @@ -217,7 +229,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=stars"
},
"10": {
"11": {
"@type": "SoftwareApplication",
"identifier": "stringr",
"name": "stringr",
Expand All @@ -229,7 +241,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=stringr"
},
"11": {
"12": {
"@type": "SoftwareApplication",
"identifier": "terra",
"name": "terra",
Expand All @@ -241,7 +253,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=terra"
},
"12": {
"13": {
"@type": "SoftwareApplication",
"identifier": "tidync",
"name": "tidync",
Expand All @@ -253,7 +265,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=tidync"
},
"13": {
"14": {
"@type": "SoftwareApplication",
"identifier": "withr",
"name": "withr",
Expand All @@ -267,7 +279,7 @@
},
"SystemRequirements": null
},
"fileSize": "329.335KB",
"fileSize": "1628.623KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down

0 comments on commit c283a1d

Please sign in to comment.