You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: vignettes/credential-scraping.Rmd
+73
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,79 @@ dbDisconnect(file_conn)
115
115
dbDisconnect(source_conn)
116
116
```
117
117
118
+
### Scraping one user's API tokens
119
+
120
+
Scraping one user's API tokens and putting them in a new, local sqlite DB for use.
121
+
122
+
You must provide the username in the API_USER environment variable or on the command line. To specify it on the command line via `Rscript` and specify a REDCap username. e.g.
123
+
124
+
```sh
125
+
Rscript scrape_one_user.R jane_doe
126
+
```
127
+
128
+
```{r, eval = FALSE}
129
+
library(redcapcustodian)
130
+
library(DBI)
131
+
library(tidyverse)
132
+
library(dotenv)
133
+
134
+
# Get the username provided on the command line if one is provided.
135
+
# Otherwise, get the username form the environment.
136
+
# Otherwise, exit.
137
+
args <- commandArgs(trailingOnly = TRUE)
138
+
if (length(args) > 0) {
139
+
# Use the command line argument
140
+
username <- args
141
+
} else if (Sys.getenv("API_USER") != "") {
142
+
# Use the environment variable
143
+
username <- Sys.getenv("API_USER")
144
+
} else {
145
+
# Exit
146
+
warning("Please provide a username that whose API tokens you want to read either on the command line or via the API_USER environment variable. No action taken.")
147
+
quit()
148
+
}
149
+
150
+
# Creates the credentials file if one does not exists.
0 commit comments