|
| 1 | +rm(list = ls()) |
| 2 | + |
| 3 | +args <- commandArgs(TRUE) |
| 4 | +wd <- args[1] |
| 5 | +setwd(wd) |
| 6 | + |
| 7 | +renv::activate() |
| 8 | +renv::restore(lockfile = '../renv.lock') |
| 9 | +Sys.setlocale(category = "LC_ALL", locale = "en_US.UTF-8") |
| 10 | + |
| 11 | +library(jsonlite) |
| 12 | +library(rbace) |
| 13 | +library(logging) |
| 14 | + |
| 15 | +source('utils.R') |
| 16 | +if (Sys.getenv("LOGLEVEL") == "DEBUG") { |
| 17 | + DEBUG <- FALSE |
| 18 | +} else { |
| 19 | + DEBUG <- TRUE |
| 20 | +} |
| 21 | + |
| 22 | +if (DEBUG == TRUE) { |
| 23 | + setup_logging('DEBUG') |
| 24 | +} else { |
| 25 | + setup_logging('INFO') |
| 26 | +} |
| 27 | + |
| 28 | +log <- getLogger('update_contentproviders') |
| 29 | + |
| 30 | +output_path <- if (length(args) >= 2) args[2] else { |
| 31 | + file.path(wd, "../../workers/common/common/contentproviders.json") |
| 32 | +} |
| 33 | +output_path <- normalizePath(output_path, mustWork = FALSE) |
| 34 | + |
| 35 | +tryCatch({ |
| 36 | + contentproviders <- bs_repositories("") |
| 37 | + if (is.null(contentproviders) || nrow(contentproviders) == 0) { |
| 38 | + stop("No content providers retrieved.") |
| 39 | + } |
| 40 | + triple <- list(name = "GoTriple", internal_name = "fttriple") |
| 41 | + contentproviders <- rbind(contentproviders, triple) |
| 42 | + |
| 43 | + write(toJSON(contentproviders, pretty = TRUE), file = output_path) |
| 44 | + log$info(paste("contentproviders.json updated:", output_path, |
| 45 | + "—", nrow(contentproviders), "entries")) |
| 46 | +}, error = function(err) { |
| 47 | + log$error(paste("Content provider update failed", "base", |
| 48 | + "update_contentproviders", "", err, sep = "||")) |
| 49 | + quit(status = 1) |
| 50 | +}) |
0 commit comments