-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_Monthly_Message_Copy.R
More file actions
63 lines (51 loc) · 2.08 KB
/
_Monthly_Message_Copy.R
File metadata and controls
63 lines (51 loc) · 2.08 KB
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
# Get all new WEA messages and move to
# "CMAS_Alerts_Processed" sheet
## Install packages ##
# if (require(tidyverse) == FALSE) {
# install.packages("tidyverse")
#
# }
# if (require(googlesheets) == FALSE) {
# install.packages("googlesheets")
#
# }
library(tidyverse)
library(lubridate)
library(googlesheets)
##
NewCMASImport <- function() { #copies new messages into main sheet
#browser()
raw <- gs_key("1GnchiRm2TXgQ1TpTGcsCIGggIjEIsd6TeuVyY_s4a3U",
visibility = "private") #CMAS Alerts
full <- gs_key("1Xw4JefUCS4HHQ0KpvKhr-DjklqzhH3_CeA-zhoAuQfI",
visibility = "private") #CMAS_Alerts_Processed
ss_new <<- full
all_cmas <<- gs_read_csv(ss = ss_new
, col_names = c("rec_time", "cmac", "full_text")
, coltypes = "Tcc", skip = 1, trim_ws = TRUE)
msg_last <- all_cmas %>%
select(rec_time) %>%
tail(1) %>%
as.character() %>%
mdy_hm()
print(paste("The last update was", msg_last))
msg_new <- gs_read_listfeed(raw
, col_names = c("rec_time", "cmac", "full_text")
, coltypes = "Tcc", skip = 1, trim_ws = TRUE) %>%
mutate(rec_time = mdy_hm(rec_time)) %>%
filter(rec_time > msg_last) %>%
mutate(rec_time =
paste0(
month(rec_time, label = TRUE,abbr = FALSE), " ",
day(rec_time), ", ",
year(rec_time)," at ",
stringr::str_pad(hour(rec_time),width = 2,side = "left", pad = "0"), ":",
stringr::str_pad(minute(rec_time),width = 2,side = "left", pad = "0")
))
if (length(msg_new$rec_time)< 1) {
message("There have been no new messages since your last import.")
} else {
print(paste("There have been", length(msg_new$rec_time), "alerts since your last import."))
gs_add_row(ss = full, ws = 1, input = msg_new, verbose = TRUE)
}
}