-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdvancedSearchExtension_Update_CloudVPS.R
139 lines (122 loc) · 5 KB
/
AdvancedSearchExtension_Update_CloudVPS.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
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env Rscript
### ---------------------------------------------------------------------------
### --- Advanced Search Extension Dashboard, v2.0 Beta 0.1
### --- Script: AdvancedSearchExtension_Update_CloudVPS.R, v. Beta 0.1
### ---------------------------------------------------------------------------
### --- DESCRIPTION:
### --- AdvancedSearchExtension_Update_CloudVPS.R runs on cron from
### --- wikidataconcepts.eqiad.wmflabs checking changes in
### --- https://analytics.wikimedia.org/datasets/wmde-analytics-engineering/TechnicalWishes/AdvancedSearchExtension/
### --- onto which the /srv/published-datasets/wdcm from stat1007 is mapped.
### --- The script updates the WMDE Advanced Search Extension Dashboard
### ---------------------------------------------------------------------------
### ---------------------------------------------------------------------------
### --- LICENSE:
### ---------------------------------------------------------------------------
### --- GPL v2
### ---
### --- AdvancedSearchExtension_Update_CloudVPS.R
### --- is free software: you can redistribute it and/or modify
### --- it under the terms of the GNU General Public License as published by
### --- the Free Software Foundation, either version 2 of the License, or
### --- (at your option) any later version.
### ---
### --- AdvancedSearchExtension_Update_CloudVPS.R
### --- is distributed in the hope that it will be useful,
### --- but WITHOUT ANY WARRANTY; without even the implied warranty of
### --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### --- GNU General Public License for more details.
### ---
### --- You should have received a copy of the GNU General Public License
### --- along with AdvancedSearchExtension_Update_CloudVPS.R
### --- If not, see <http://www.gnu.org/licenses/>.
### ---------------------------------------------------------------------------
# - libraries
library(httr)
library(curl)
library(stringr)
library(XML)
# - toReport:
print(paste0("TW: Advanced Search Extension update started on: ", as.character(Sys.time())))
### --- Config File
### --- Read WDCM paramereters
# - fPath: where the scripts is run from?
fPath <- as.character(commandArgs(trailingOnly = FALSE)[4])
fPath <- gsub("--file=", "", fPath, fixed = T)
fPath <- unlist(strsplit(fPath, split = "/", fixed = T))
fPath <- paste(
paste(fPath[1:length(fPath) - 1], collapse = "/"),
"/",
sep = "")
params <- xmlParse(paste0(fPath, 'config_AdvancedSearchExtension_Update_CloudVPS.xml'))
params <- xmlToList(params)
# - toReport:
print(paste0("Download data: Step 1. ", as.character(Sys.time())))
### --- data
h <- new_handle()
# - set curl options:
handle_setopt(h,
copypostfields = "TW Advanced Search Extension Dashboard");
handle_setheaders(h,
"Cache-Control" = "no-cache"
)
# - download:
curl_download(url = params$asExtensionUpdateRemotePath,
handle = h,
destfile = params$asExtensionUpdateLocalPath)
# - toReport:
print(paste0("Download data: Step 2. cirrusSearchUpdate.csv ", as.character(Sys.time())))
# - cirrusSearchUpdate.csv
# - set curl options:
handle_setopt(h,
copypostfields = "TW Advanced Search Extension Dashboard");
handle_setheaders(h,
"Cache-Control" = "no-cache"
)
# - download:
curl_download(url = params$cirrusSearchUpdateRemotePath,
handle = h,
destfile = params$cirrusSearchUpdateLocalPath)
# - toReport:
print(paste0("Download data: Step 3. cirrusSearchUpdateKeywords.csv ", as.character(Sys.time())))
# - cirrusSearchUpdateKeywords.csv
# - set curl options:
handle_setopt(h,
copypostfields = "TW Advanced Search Extension Dashboard");
handle_setheaders(h,
"Cache-Control" = "no-cache"
)
# - download:
curl_download(url = params$cirrusSearchUpdateKeywordsRemotePath,
handle = h,
destfile = params$cirrusSearchUpdateKeywordsLocalPath)
# - toReport:
print(paste0("Download data: Step 4. Rds files ", as.character(Sys.time())))
# - download .Rds data:
# - list files:
url <- params$updateRemoteDir
page <- as.character(GET(url))
links <- str_extract_all(page, "<a href=.+>.+</a>")
links <- sapply(links, function(x) {str_extract_all(x, ">.+<")})
links <- sapply(links, function(x) {gsub('^>|"|<$|>|<', "", x)})
links <- links[3:length(links)]
links <- links[grepl(".Rds", links, fixed = T)]
for (i in 1:length(links)) {
# - download:
curl_download(url =
paste0(params$updateRemoteDir,
links[i]),
handle = h,
destfile = paste0(params$updateLocalDir,
links[i])
)
}
### --- copy data:
# - toReport:
print(paste0("TW: Advanced Search Extension copy files in production started on: ", as.character(Sys.time())))
system(paste0('sudo cp ',
params$updateLocalDir, '* ',
params$updateProductionDir),
wait = T)
# - toReport:
print(paste0("TW: Advanced Search Extension update completed on: ", as.character(Sys.time())))