-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSFdescripts.R
128 lines (85 loc) · 3.46 KB
/
OSFdescripts.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# update descriptions in OSF projects
# OSF / SPNHC 2019
library("httr")
library("osfr")
library("readr")
library("jsonlite")
# Setup Notes: ####
#
# In .Renviron, add this line:
# OSF_PAT = "[OSF token]"
#
# API rate limit:
# = 10,000/day with token
# = 100/day without
#
# Setup OSF API token & URL
osf_pat <- Sys.getenv("OSF_PAT")
url <- "https://api.osf.io/v2/"
node_id_test <- "j3dk2/"
# url_test <- "https://api.test.osf.io/v2/"
# Import submission form CSV
oldSPNHCabsBU <- read_csv("SPNHC2019abstracts_prep_20190319.csv")
SPNHCabsBU <- read_csv("SPNHC2019abstracts_prep_20190329.csv")
# SPNHCabs <- SPNHCabsBU[is.na(SPNHCabsBU$`Abstract Title`) == F,]
SPNHCabs <- SPNHCabsBU[grepl("done", tolower(SPNHCabsBU$divvy)),]
SPNHCabs$osf_node_id <- gsub("https://osf.io/", "", SPNHCabs$osf_url)
SPNHCabs$osf_node_id <- gsub("/", "", SPNHCabs$osf_node_id)
# For each abstract: ####
projCheckList <- list()
projStatusList <- list()
projTXTList <- list()
print(Sys.time())
for (i in 2:NROW(SPNHCabs)) {
# Add OSF SPNHC metg URL to abstract descriptions
# description <- "Part of SPNHC 2019 | https://osf.io/view/SPNHC2019"
patchprojTXT <- list("type" = "nodes",
"id" = SPNHCabs$osf_node_id[i], # "j3dk2", #
"attributes" = list( # "description" = description,
"public" = TRUE)
)
patchprojFIN <- list("data" = patchprojTXT)
patchproj <- jsonlite::toJSON(patchprojFIN,
pretty = TRUE,
auto_unbox = TRUE)
projCheck <- PATCH(url = paste0(url, "nodes/", SPNHCabs$osf_node_id[i], "/"), # j3dk2/"), #
config = add_headers(Authorization = paste0("Bearer ", osf_pat)),
content_type_json(),
body = patchproj,
encode = "json")
projStatusTags <- message_for_status(projCheck)
projCheckTXT <- jsonlite::fromJSON(content(projCheck, "text"))
# projCheckList[i] <- projCheck
# projStatusList[i] <- projStatusTags
# projTXTList[i] <- projCheckTXT
print(i)
Sys.sleep(1)
}
print(Sys.time())
# Get node attributes (titles + url + description)
# (get contributors later)
nodes_info <- list(list(list(), list()))
googleCheck <- data.frame("osf_url" = "",
"title" = "",
"descrip_check" = "",
stringsAsFactors = F)
print(Sys.time())
for (i in 2:NROW(SPNHCabs)) {
# GET OSF proj data
getnode <- GET(paste0(url, "nodes/", SPNHCabs$osf_node_id[i]))
getnodeTXT <- jsonlite::fromJSON(content(getnode, "text"))
nodes_info[i][[1]] <- getnodeTXT
projStatusTags <- message_for_status(getnode)
googleCheck[i,] <- c("osf_node_id" = SPNHCabs$osf_node_id[i],
"title" = getnodeTXT$data$attributes$title,
"descrip_check" = getnodeTXT$data$attributes$description)
print(i)
Sys.sleep(3)
}
print(Sys.time())
googleUpdate <- merge(SPNHCabs, googleCheck,
by = "osf_node_id",
all = TRUE)
googleUpdate$titleCheck <- "yes"
googleUpdate$titleCheck[tolower(googleUpdate$title) != tolower(googleUpdate$`Abstract Title`)] <- "no"
write_csv(googleUpdate, path = paste0("googleUpdate",Sys.Date(),".csv"))