add tumblr printer

This commit is contained in:
Paul Tagliamonte 2013-06-25 21:47:54 -04:00
parent 612b9f783f
commit 9b45dd4ffe

22
eg/lxml/parse-tumblr.hy Normal file
View File

@ -0,0 +1,22 @@
;;; Hy tumblr printer.
;;; Copyright (c) Paul R. Tagliamonte, 2013, MIT/Expat license.
(import [urllib2 [urlopen]]
[lxml [etree]]
[sys [argv]])
(defn get-rss-feed-name [tumblr]
(kwapply (.format "http://{tumblr}.tumblr.com/rss") {"tumblr" tumblr}))
(defn get-rss-feed [tumblr]
(.parse etree (urlopen (get-rss-feed-name tumblr))))
(defn print-posts [tumblr]
(for [post (.xpath (get-rss-feed tumblr) "//item/title")]
(print post.text)))
(if (slice argv 2)
(print-posts (get argv 2))
(print-posts "this-plt-life"))