Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Last active December 17, 2015 11:49
Show Gist options
  • Save jackrusher/5605471 to your computer and use it in GitHub Desktop.
Save jackrusher/5605471 to your computer and use it in GitHub Desktop.
(ns tumblr-backup.core
(:use [clojure.xml :as xml]))
(defn build-tumblr-url [start howmany]
(format "http://blog.jackrusher.com/api/read/?start=%d&num=%d" start howmany))
(defn get-post-count []
(read-string (-> (xml/parse (build-tumblr-url 0 0)) :content second :attrs :total)))
(defn spit-post [post]
(let [post (-> post :content second :content first)
attrs (:attrs post)
filename (str (:unix-timestamp attrs) "-" (:slug attrs) ".xml")]
(println filename)
(spit filename post)))
(defn backup-tumblr []
(doseq [post-num (range (get-post-count))]
(spit-post (xml/parse (build-tumblr-url post-num 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment