#!/usr/bin/Rscript --vanilla # input is a pre-made list of files ending in html called ../htmlist # (see below). This is easily modified. # output is a rss feed that is valid according to the w3c validator # this is called rss.xml # additional output is a text version, which can be sent by email # called notify.txt # notification list - THIS MUST BE EDITED EACH ISSUE Notify <- "Table of contents:\n\nhttp://journal.sjdm.org/vol16.6.html\n\n(The table of contents provides access to pdf and html versions of each article, and the data if not linked from the article.)\n\nArticles\n\n" # funtion to extract tags from .rdf Get <- function(x,y) {unlist(strsplit(r1[x],split=":"))[y]} # construct an item for the rss feed. # assume that Abstract is followed by Keywords in ReDIFF # key words are not included in the feed or the notification email Makeitem <- function() { Author <- "" Abstract <- "" Pdf <- "" j <- 0 for (i in 1:length(r1)) { if (Get(i,1)=="Author-Name") {Author <- paste(Author,Get(i,2),sep=" ---")} if (Get(i,1)=="File-URL" & Pdf=="") {Pdf <- paste(Get(i,2),Get(i,3),sep=":")} if (Get(i,1)=="Title") {Title <- substring(r1[i],8)} if (Get(i,1)=="Abstract") {j <- i+1; break}} Pdf <- sub(" ","",Pdf) for (i in j:length(r1)) { if (Get(i,1)!="Keywords") {Abstract <- paste(Abstract,r1[i],sep="\n")} else {break}} return(paste("\n\n",Title,Author,"", "\n",Pdf,"","\n", "\n",Abstract, "]]>\n",sep="")) } # construct an item for the notification list, Makenote <- function() { Author <- "" Abstract <- "" Pdf <- "" for (i in 1:length(r1)) { if (Get(i,1)=="Author-Name") {Author <- paste(Author,Get(i,2),sep=" ---")} if (Get(i,1)=="File-URL" & Pdf=="") {Pdf <- paste(Get(i,2),Get(i,3),sep=":")} if (Get(i,1)=="Title") {Title <- substring(r1[i],8)} if (Get(i,1)=="Abstract") {j <- i+1; break}} for (i in j:length(r1)) { if (Get(i,1)!="Keywords") {Abstract <- paste(Abstract,r1[i])} else {break}} Abstract <- gsub(" "," ",Abstract) Abstract <- gsub(" "," ",Abstract) return(paste("-------------------------\n\n",Title,"\n\n",Author,"\n\n",Pdf,"\n\n",Abstract,"\n\n")) } # top of rss feed Rss <- " Judgment and Decision Making, current contents http://journal.sdm.org/ Judgment and Decision Making, current contents Jonathan Baron en-US " # middle of rss feed, after list of items Rss1 <- "" # get list of rdf files. In the list, each file ends with html, so must be cut off. Htmlist <- scan(file="../htmlist",what="character",sep="\n") List <- sapply(Htmlist,function(x) unlist(strsplit(x,split="/"))[3]) List <- gsub(".pdf",".rdf",List) List <- gsub("jdm","../",List) # main loop, assumes .rdf files in parent directory for (k in List) {r1 <- scan(file=k,what="character",sep="\n") Rss1 <- paste(Rss1,Makeitem(),sep="") # add detailed item to end of Rss1 Rss <- paste(Rss,"\n",sep="") # short list of items Notify <- paste(Notify,Makenote())} # for notificattion list # rss feed has 2 parts, so put them together Rss1 <- paste(Rss,Rss1,"",sep="\n") # write the output write(Rss1,file="rss.xml") # write rss feed write(Notify,file="notify.txt") # write notification list