## 报健康v0.1.3 (2021-12-11)
# - cug 门户网站网址修改
library(curlR)
print(Sys.time())
## 成功登陆地大信息门户
login_CUG <- function() {
p <- getOption("curlR.browser")
p$navigate("http://one.cug.edu.cn/tp_up/v1?m=up#act=portal/viewhome")
p$findElement("css selector", ".qq") %>% clickElement()
login_qq.pwd(p)
}
# getElementByClass(p, "//[@class]sjakvxbio OCjauhgy7jz")
report_health <- function() {
# tryCatch({
# navigate to the page of health report
p <- getOption("curlR.browser")
go(p, "http://rsfw.cug.edu.cn/rsfw/sys/lwReportEpidemic/*default/index.do#/")
Sys.sleep(5)
# 判断填报成功与否
nodes <- p %>% ele_find_all("//*[contains(@class, 'sjakvxbio OCjauhgy7jz')]")
dates <- ele_text(nodes)
cat("Reported Dates: \n")
print(dates)
p$findElement("css selector", ".geuhjrnk") %>% clickElement() # 填报
Sys.sleep(3)
p$findElement("css selector", "div.OPjctwlgzsl button.mt-btn-primary") %>% clickElement() # 提交
Sys.sleep(3)
p$findElement("css selector", "button.mint-msgbox-confirm") %>% clickElement() # 确认
# }, error = function(e) {
# message(sprintf("%s", e$message))
# Sys.sleep(5)
# cat(sprintf(("[ok] already reported\n")))
# })
}
port <- 4445
main <- function() {
kill_selenium(port)
p <- init_selenium(port, browserName = "chrome")
on.exit({
p$closeall()
kill_selenium(port)
})
tryCatch(
{
login_CUG()
Sys.sleep(5)
report_health()
},
error = function(e) {
message(sprintf("%s", e$meage))
cat("[e] stopping ...")
}
)
}
main()
# system("taskkill /IM selenium-server -f")
if (0) {
# create daily task in windows
infile <- glue("{getwd()}/examples/CUG_report_health.R") # change to your path
task_create(
taskname = "CUG_ReportHealth", rscript = infile,
schedule = "DAILY", starttime = "07:10"
)
task_ls("CUG_ReportHealth")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.