Skip to content

Commit

Permalink
patch for regions with no series
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Feb 19, 2024
1 parent 5271904 commit 4868cd3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: OSDRegistry
Type: Package
Title: Official Series Description (OSD) Registry
Version: 0.6.0
Version: 0.6.1
Author: Soil Survey Staff
Maintainer: Andrew G. Brown <andrew.g.brown@usda.gov>
Description: Version control solution for Official Series Descriptions (OSDs; <https://soilseries.sc.egov.usda.gov/>) and the Series Classification database. Official "series" are soil types used by the USDA-NRCS and the National Cooperative Soil Survey program.
Expand Down
26 changes: 14 additions & 12 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,22 @@
osd_result2 <- try(rvest::session_submit(osd_session, osd_request2, "view"))
Sys.sleep(0.5)

## Create download directories
# ideally we would be able to use RSelenium and browser options to go right to /raw
target_dir <- file.path(getwd(), 'raw')
if (!dir.exists(target_dir))
dir.create(target_dir, recursive = TRUE)

# but it may download to the default path (user Downloads folder)
default_dir <- file.path(path.expand('~'), "Downloads")
# if (!dir.exists(default_dir))
# dir.create(default_dir, recursive = TRUE)

## -- STEP 2 - VIEW results (in separate window for "big" queries)
if (inherits(osd_result2, 'try-error')) {
# osd_result2 <- try(submit_form(osd_session, osd_request2, "download"))
stop('This utility only works with queries that require a separate page for viewing.')
message('This utility only works with queries that require a separate page for viewing. Skipping region: ', x)
return(NA_character_)
} else {
osd_hidden_report <- rvest::html_form(osd_result2)[[1]]$fields$hidden_report_filename
url2 <- sprintf("https://soilseries.sc.egov.usda.gov/osdquery_view.aspx?query_file=%s&",
Expand All @@ -52,16 +64,6 @@
osd_result3 <- rvest::session_submit(osd_session2, osd_request3, submit = "download")
remDr$navigate(osd_result3$url)

# ideally we would be able to use RSelenium and browser options to go right to /raw
target_dir <- file.path(getwd(), 'raw')
if (!dir.exists(target_dir))
dir.create(target_dir, recursive = TRUE)

# but it may download to the default path (user Downloads folder)
default_dir <- file.path(path.expand('~'), "Downloads")
# if (!dir.exists(default_dir))
# dir.create(default_dir, recursive = TRUE)

file_name <- list.files(target_dir, "osddwn.*zip$")
dfile_name <- list.files(default_dir, "osddwn.*zip$")

Expand Down Expand Up @@ -109,7 +111,7 @@
} else {
return(try(stop(sprintf("Problem with OSD Download for Region %s", x), call. = FALSE)))
}
file.path(default_dir, new_dfile_name)
}

file.path(default_dir, new_dfile_name)
}
7 changes: 4 additions & 3 deletions R/registry.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ refresh_registry <- function(test = FALSE, moID = 1:13, port = 4567L) {
# }

if (!inherits(res, 'try-error')) {
zips <- c(zips, res)
if (!is.na(res))
zips <- c(zips, res)
} else {
message(paste0("Error querying OSDs region (", i, ")"))
}
Expand Down Expand Up @@ -155,13 +156,13 @@ refresh_registry <- function(test = FALSE, moID = 1:13, port = 4567L) {

sc <- .download_NASIS_SC_webreport()

if (inherits(sc, 'try-error') ||
if (inherits(sc, 'try-error') ||
!inherits(sc, 'data.frame') ||
nchar(as.character(sc[1])) == 0) {
warning('Failed to update Series Classification database via NASIS Web Report', "\n\n",
sc[1], call. = FALSE)
} else {
if (!dir.exists("SC"))
if (!dir.exists("SC"))
dir.create("SC")
if (nrow(sc) > 0) {
write.csv(sc, file = file.path("SC", "SCDB.csv"), row.names = FALSE)
Expand Down

0 comments on commit 4868cd3

Please sign in to comment.