|
1 | | -prjListEmail <- function (queryEmail,ndays=60,sendEmail=TRUE) |
2 | | -{ |
3 | | - ## This funciton needs to be customized a noted below! |
4 | | - |
5 | | - # Send an Email of the projects associated with an email address |
6 | | - # to the email address. The Email address must be a match (case insensitive) |
7 | | - # to the one sepecified when the project was created. |
8 | | - |
9 | | - trim <- function (x) gsub("^\\s+|\\s+$","",x) |
10 | | - |
11 | | - if (missing(queryEmail)) stop("queryEmail must be specified") |
12 | | - # insure a single token, no blanks |
13 | | - queryEmail = scan(text=queryEmail,what="character",quiet=TRUE) |
14 | | - if (length(queryEmail) > 1) stop ("queryEmail string contains white space") |
15 | | - |
16 | | - workDirs = list.dirs("/home/shiny/FVSwork",recursive = FALSE) |
17 | | - ids = lapply(workDirs,function (x) |
18 | | - { |
19 | | - fn = paste0(x,"/projectId.txt") |
20 | | - id = NULL |
21 | | - if (file.exists(fn)) |
22 | | - { |
23 | | - id = scan(file=fn,what="character", |
24 | | - sep="\n",quiet=TRUE) |
25 | | - if (!is.null(id)) |
26 | | - { |
27 | | - info = file.info(x) |
28 | | - attr(id,"ctime") = info[1,"ctime"] |
29 | | - info = file.info(fn) |
30 | | - attr(id,"mtime") = info[1,"mtime"] |
31 | | - } |
32 | | - } |
33 | | - id |
34 | | - }) |
35 | | -##The following line needs to be edited and uncommented to replace the |
36 | | -##base web address string in the substitution |
37 | | - names (ids) = sub("/home/shiny/FVSwork", |
38 | | - "https://charcoal2.cnre.vt.edu/FVSwork",workDirs) |
39 | | - |
40 | | - rptFile = tempfile() |
41 | | - con = file(rptFile,"w") |
42 | | - |
43 | | - cat (file=con,"To:",queryEmail,"\n") |
44 | | - cat (file=con,"Subject: FVSOnline projects at Virginia Tech\n") |
45 | | - cat (file=con,"\n Projects and links for Email:",queryEmail,"\n") |
46 | | - nprjs = 0 |
47 | | - for (i in 1:length(ids)) |
48 | | - { |
49 | | - id = unlist(ids[i]) |
50 | | - nam = names(ids[i]) |
51 | | - if (is.null(id)) next |
52 | | - email = trim(scan(text=id[1],what="character",quiet=TRUE)[2]) |
53 | | - if (tolower(email) == tolower(queryEmail)) |
54 | | - { |
55 | | - nprjs = nprjs+1 |
56 | | - cat (file=con,"\n",id[1],"\n",id[2],"\n") |
57 | | - tt = format(attr(ids[i][[1]],"ctime"),usetz=TRUE) |
58 | | - cat (file=con," created at = ",tt,"\n") |
59 | | - tt = format(attr(ids[i][[1]],"mtime"),usetz=TRUE) |
60 | | - cat (file=con," last modified= ",tt,"\n") |
61 | | - tt = format(attr(ids[i][[1]],"mtime")+(86400*ndays),usetz=TRUE)#86400=seconds/day |
62 | | - cat (file=con," auto removal = ",tt,"\n") |
63 | | - cat (file=con," project link = ",nam,"\n") |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - if (nprjs == 0) cat (file=con,"\n There are no projects under this Email address.\n") |
68 | | - if (nprjs == 1) cat (file=con,"\n There is one project under this Email address.\n") |
69 | | - if (nprjs > 1) cat (file=con,"\n There are",nprjs, |
70 | | - "projects under this Email address.\n") |
71 | | - close(con) |
72 | | - |
73 | | -##Edit and uncomment the mailCmd as necessary for a given installation |
74 | | - mailCmd = paste('ssmtp -t < ',rptFile) |
75 | | - |
76 | | - if (sendEmail) system (mailCmd) else system(paste("cat",rptFile)) |
77 | | - unlink (rptFile) |
78 | | - nprjs |
79 | | -} |
80 | | - |
81 | | - |
| 1 | +prjListEmail <- function (queryEmail,ndays=60,sendEmail=TRUE) |
| 2 | +{ |
| 3 | + ## This funciton needs to be customized a noted below! |
| 4 | + |
| 5 | + # Send an Email of the projects associated with an email address |
| 6 | + # to the email address. The Email address must be a match (case insensitive) |
| 7 | + # to the one sepecified when the project was created. |
| 8 | + |
| 9 | + trim <- function (x) gsub("^\\s+|\\s+$","",x) |
| 10 | + |
| 11 | + if (missing(queryEmail)) stop("queryEmail must be specified") |
| 12 | + # insure a single token, no blanks |
| 13 | + queryEmail = scan(text=queryEmail,what="character",quiet=TRUE) |
| 14 | + if (length(queryEmail) > 1) stop ("queryEmail string contains white space") |
| 15 | + |
| 16 | + workDirs = list.dirs("/home/shiny/FVSwork",recursive = FALSE) |
| 17 | + ids = lapply(workDirs,function (x) |
| 18 | + { |
| 19 | + fn = paste0(x,"/projectId.txt") |
| 20 | + id = NULL |
| 21 | + if (file.exists(fn)) |
| 22 | + { |
| 23 | + id = scan(file=fn,what="character", |
| 24 | + sep="\n",quiet=TRUE) |
| 25 | + if (!is.null(id)) |
| 26 | + { |
| 27 | + info = file.info(x) |
| 28 | + attr(id,"ctime") = info[1,"ctime"] |
| 29 | + info = file.info(fn) |
| 30 | + attr(id,"mtime") = info[1,"mtime"] |
| 31 | + } |
| 32 | + } |
| 33 | + id |
| 34 | + }) |
| 35 | +##The following line needs to be edited and uncommented to replace the |
| 36 | +##base web address string in the substitution |
| 37 | + names (ids) = sub("/home/shiny/FVSwork", |
| 38 | + "https://charcoal2.cnre.vt.edu/FVSwork",workDirs) |
| 39 | + |
| 40 | + rptFile = tempfile() |
| 41 | + con = file(rptFile,"w") |
| 42 | + |
| 43 | + cat (file=con,"To:",queryEmail,"\n") |
| 44 | + cat (file=con,"Subject: FVSOnline projects at Virginia Tech\n") |
| 45 | + cat (file=con,"\n Projects and links for Email:",queryEmail,"\n") |
| 46 | + nprjs = 0 |
| 47 | + for (i in 1:length(ids)) |
| 48 | + { |
| 49 | + id = unlist(ids[i]) |
| 50 | + nam = names(ids[i]) |
| 51 | + if (is.null(id)) next |
| 52 | + email = trim(scan(text=id[1],what="character",quiet=TRUE)[2]) |
| 53 | + if (tolower(email) == tolower(queryEmail)) |
| 54 | + { |
| 55 | + nprjs = nprjs+1 |
| 56 | + cat (file=con,"\n",id[1],"\n",id[2],"\n") |
| 57 | + tt = format(attr(ids[i][[1]],"ctime"),usetz=TRUE) |
| 58 | + cat (file=con," created at = ",tt,"\n") |
| 59 | + tt = format(attr(ids[i][[1]],"mtime"),usetz=TRUE) |
| 60 | + cat (file=con," last modified= ",tt,"\n") |
| 61 | + tt = format(attr(ids[i][[1]],"mtime")+(86400*ndays),usetz=TRUE)#86400=seconds/day |
| 62 | + cat (file=con," auto removal = ",tt,"\n") |
| 63 | + cat (file=con," project link = ",nam,"\n") |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + if (nprjs == 0) cat (file=con,"\n There are no projects under this Email address.\n") |
| 68 | + if (nprjs == 1) cat (file=con,"\n There is one project under this Email address.\n") |
| 69 | + if (nprjs > 1) cat (file=con,"\n There are",nprjs, |
| 70 | + "projects under this Email address.\n") |
| 71 | + close(con) |
| 72 | + |
| 73 | +##Edit and uncomment the mailCmd as necessary for a given installation |
| 74 | + mailCmd = paste('ssmtp -t < ',rptFile) |
| 75 | + |
| 76 | + if (sendEmail) system (mailCmd) else system(paste("cat",rptFile)) |
| 77 | + unlink (rptFile) |
| 78 | + nprjs |
| 79 | +} |
| 80 | + |
| 81 | + |
0 commit comments