Skip to content

Commit

Permalink
setup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ha0ye committed Nov 14, 2023
1 parent 3800a8e commit 51bf86d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
googledrive,
googlesheets4
26 changes: 13 additions & 13 deletions R/access-files.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
library("googledrive")
run = FALSE
if (run)
{
do_auth()

source("api-functions.R")
c4r_drive <- "(C4R) Community for Rigor"

drive_auth(token = decrypt_gdrive_token())
# get some info about working with google drive
drive_find("Unit Roadmap", shared_drive = c4r_drive)

c4r_drive <- "(C4R) Community for Rigor"
drive_about()$exportFormats

# get some info about working with google drive
drive_find("Unit Roadmap", shared_drive = c4r_drive)

drive_about()$exportFormats

# do some stuff
roadmap_file <- drive_find("Unit Roadmap - Sample Size and Power Calculation",
shared_drive = c4r_drive)
downloaded_file <- drive_download(roadmap_file, type = "rtf")
# do some stuff
roadmap_file <- drive_find("Unit Roadmap - Sample Size and Power Calculation",
shared_drive = c4r_drive)
downloaded_file <- drive_download(roadmap_file, type = "rtf")


}
13 changes: 10 additions & 3 deletions R/api-functions.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
do_auth <- function()
{
my_token <- decrypt_gdrive_token()
googledrive::drive_auth(token = my_token)
googlesheets4::gs4_auth(token = my_token)
}

decrypt_gdrive_token <- function()
{
token <- NULL
if (gargle:::secret_has_key("GDRIVE_KEY"))
{
token <- gargle::secret_read_rds(".secrets/gdrive-token.rds",
token <- gargle::secret_read_rds(".secrets/gdrive-token.rds",
key = "GDRIVE_KEY")
}

invisible(token)
}
}
16 changes: 16 additions & 0 deletions R/logging.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
log_action <- function(action = "", note = "")
{
my_log <- access_log()
log_row <- data.frame(datetime = format(Sys.time(), "%Y-%M-%d %X %Z"),
action = action,
note = note)
googlesheets4::sheet_append(my_log, log_row)
}

access_log <- function()
{
do_auth()
googledrive::drive_get("https://docs.google.com/spreadsheets/d/1n3rmcM94r_RL-QPTEuxP2D2g2BlrB_Hhdw1Ag_FkUsA/edit?usp=sharing")
}


0 comments on commit 51bf86d

Please sign in to comment.