generated from OxfordIHTM/ihtm-targets-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add functions and targets for downloading agriculture forecasts; fix …
…add farm weather forecasts download targets #63
- Loading branch information
1 parent
19b6c14
commit 96cb577
Showing
9 changed files
with
109 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ on: | |
schedule: | ||
- cron: "0 7 * * *" | ||
workflow_dispatch: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
deploy-targets-download: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: test targets forecasts agriculture | ||
|
||
on: | ||
pull_request: | ||
branches: [main, master] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test-targets-forecasts-agriculture: | ||
runs-on: ubuntu-latest | ||
container: rocker/tidyverse:4.4.1 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install system dependencies | ||
run: | | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
libxt6 libglpk-dev libpoppler-cpp-dev libmagick++-dev \ | ||
libtesseract-dev libleptonica-dev tesseract-ocr-eng | ||
- name: Install packages from renv.lock (with cache) | ||
if: ${{ !env.ACT }} | ||
uses: r-lib/actions/setup-renv@v2 | ||
with: | ||
cache-version: 2 | ||
|
||
- name: Install packages from renv.lock (local, no cache) | ||
if: ${{ env.ACT }} | ||
run: | | ||
renv::restore() | ||
shell: Rscript {0} | ||
|
||
- name: Run workflow | ||
run: | | ||
targets::tar_make(dplyr::starts_with("forecasts_agriculture")) | ||
shell: Rscript {0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#' | ||
#' Download PAGASA daily agriculture forecasts | ||
#' | ||
#' @param directory Path to directory to download the daily agriculture | ||
#' forecast PDF to. | ||
#' @param overwrite Logical. Should an existing file with the same file path be | ||
#' overwritten? Default is FALSE. | ||
#' | ||
#' @returns The path to the downloaded daily agriculture forecast PDF. | ||
#' | ||
#' @examples | ||
#' forecasts_agriculture_download() | ||
#' | ||
#' @rdname forecasts_agriculture | ||
#' @export | ||
#' | ||
|
||
forecasts_agriculture_download <- function(directory = "data-raw/forecasts_agriculture", | ||
overwrite = FALSE) { | ||
if (weekdays(Sys.Date()) %in% c("Saturday", "Sunday")) { | ||
.url <- "https://pubfiles.pagasa.dost.gov.ph/pagasaweb/files/agriculture/weekend_special_farm_forecast/weekend_special_farm_weather_forecast.pdf" | ||
} else { | ||
.url = "https://pubfiles.pagasa.dost.gov.ph/pagasaweb/files/agriculture/farm_weather_forecast/farm_weather_forecast.pdf" | ||
} | ||
|
||
## Quiet down ssl verification ---- | ||
#h <- curl::new_handle() | ||
#curl::handle_setopt(h, .list = list(ssl_verifypeer = 0L)) | ||
|
||
## Create file path to download ---- | ||
destfile <- file.path(directory, paste0(Sys.Date(), ".pdf")) | ||
|
||
## Create directories as needed ---- | ||
if (!dir.exists(directory)) dir.create(directory) | ||
|
||
## Download PDF ---- | ||
if ( | ||
!destfile %in% list.files(directory, full.names = TRUE) | | ||
length(list.files(directory, full.names = TRUE)) == 0 | ||
) { | ||
## Download file ---- | ||
download.file(url = .url, destfile = destfile) | ||
#curl::curl_download(url = url, destfile = destfile, handle = h) | ||
} else { | ||
if (overwrite) { | ||
## Download file ---- | ||
download.file(url = .url, destfile = destfile) | ||
#curl::curl_download(url = url, destfile = destfile, handle = h) | ||
} | ||
} | ||
|
||
## Return path to downloaded file ---- | ||
destfile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.