Skip to content

Instantly share code, notes, and snippets.

@kedare
Created October 21, 2014 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kedare/d4ac3c15f9d8424a84aa to your computer and use it in GitHub Desktop.
Save kedare/d4ac3c15f9d8424a84aa to your computer and use it in GitHub Desktop.
xml2json = require "xml2json"
fs = require "fs"
util = require "util"
request = require "request"
#sleep = require "sleep"
tumblr_name = process.argv[2]
api_endpoint = util.format "http://%s.tumblr.com/api/read", tumblr_name
start = 0
num = 50
post_count = 0
download = (uri, filename) ->
request(uri).pipe(fs.createWriteStream(filename))
while post_count < 5
console.log "H"
page_uri = util.format "%s?type=photo&start=%s&num=%s", api_endpoint, start, num
start = start+num
post_count = post_count+1
request page_uri, (error, response, body) ->
console.log util.format "Downloading %s", page_uri
data_xml = body
data_json = JSON.parse xml2json.toJson data_xml
#post_count = data_json["tumblr"]["posts"]["post"].length
start = num*post_count
for post in data_json["tumblr"]["posts"]["post"]
post_id = post["id"]
post_date = post["date-gmt"].split(" ")[0]
for photo in post["photo-url"]
if photo["max-width"] == 1280
outname = util.format "%s-%s-%s.%s", tumblr_name, post_date, post_id, photo["$t"].split(".").slice(-1)[0]
download photo["$t"], outname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment