Skip to content

Instantly share code, notes, and snippets.

@atbradley
Last active October 7, 2015 15:08
Show Gist options
  • Save atbradley/3184120 to your computer and use it in GitHub Desktop.
Save atbradley/3184120 to your computer and use it in GitHub Desktop.
Post to Tumblr (as draft) when generating HTML from R Markdown (R Studio) No longer works--Tumblr's eliminated v1 of their API for everything but retrieving posts.
#in .Rprofile:
tumblr.user <- "[email protected]"
tumblr.pass <- "tumblrPassword"
library(markdown)
library(httr)
options(rstudio.markdownToHTML =
function(i,o) {
markdownToHTML(i,o,fragment.only=TRUE)
#Post as a draft to Tumblr.
cat("\n","Enter a title, or a blank line for none.","\n")
title<-scan(what="character", n=1, sep="\n")
txt <- paste(readLines(o), collapse="\n")
body <- list(email = tumblr.user,
password = tumblr.pass,
type = "regular",
body = txt,
state = "draft")
#If no title was entered, don't send one to Tumblr.
if(length(title) == 1) body$title <- title
POST("http://www.tumblr.com/api/write", body=body)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment