Skip to content

Instantly share code, notes, and snippets.

@mrdwab
Created February 26, 2013 09:48
Show Gist options
  • Save mrdwab/5037343 to your computer and use it in GitHub Desktop.
Save mrdwab/5037343 to your computer and use it in GitHub Desktop.
Reads the sqlite database created by CintaNotes.
print.cintanotes <- function(x, ...) {
for (i in 1:nrow(x)) {
cat("#", x[i, 2], "\n\n")
cat(paste("Posted on *", x[i, 4], "*\n\n", sep = ""))
cat(x[i, 3], "\n\n")
if (x[i, 5] != "") {
cat("Links: ", x[i, 5], "\n\n")
}
if (!is.na(x[i, 6])) {
cat("Tags: ", x[i, 6], "\n\n")
}
cat("--------------------------\n\n\n\n")
}
}
readCintaNotesDB <- function(DBLocation) {
require(sqldf)
GetTables <- paste("select * from",
c("NoteCache", "Notes", "NotesData_content",
"Notes_Tags", "Tags"))
TableNames <- c("metadata", "sources", "content", "tagindex", "tags")
output <- lapply(GetTables, function(x) sqldf(x, dbname = DBLocation))
names(output) <- TableNames
output$metadata$created <- format(as.Date(output$metadata$created,
format = "%m/%d/%Y"),
"%d %B %Y")
T1 <- merge(merge(output[[1]], output[[2]],
by.x = "noteid", by.y = "id", all = TRUE),
output[[3]], by.x = "noteid", by.y = "docid", all = TRUE)
T2 <- merge(output[[4]], output[[5]], by.x = "tagid", by.y = "id", all = TRUE)
T2 <- aggregate(name ~ noteid, T2, paste, collapse = ", ")
output <- merge(T1, T2, all = TRUE)
output <- output[c(1, 9, 10, 2, 6, 11)]
names(output) <- c("noteid", "title", "text", "date", "references", "tags")
output$text <- gsub("\n", "\n\n", output$text)
class(output) <- c("cintanotes", class(output))
output
}
@mrdwab
Copy link
Author

mrdwab commented Feb 26, 2013

Load both functions, then use it something like:

temp <- readCintaNotesDB("~/Dropbox/Notebook/cintanotes.db")
capture.output(temp, file = "SomeFileName.txt")

To get a relatively cleaned-up version of your CintaNotes data that can be converted to a PDF using Pandoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment