2013-06-25 21:47:54 -04:00
|
|
|
;;; Hy tumblr printer.
|
|
|
|
;;; Copyright (c) Paul R. Tagliamonte, 2013, MIT/Expat license.
|
|
|
|
|
|
|
|
|
2014-03-18 11:13:51 +00:00
|
|
|
(import [lxml [etree]]
|
2013-06-25 21:47:54 -04:00
|
|
|
[sys [argv]])
|
|
|
|
|
2014-03-18 11:13:51 +00:00
|
|
|
(try
|
|
|
|
(import [urllib.request [urlopen]])
|
2015-08-09 00:41:11 -06:00
|
|
|
(except [ImportError]
|
2014-03-18 11:13:51 +00:00
|
|
|
(import [urllib2 [urlopen]])))
|
2013-06-25 21:47:54 -04:00
|
|
|
|
|
|
|
(defn get-rss-feed-name [tumblr]
|
2014-01-22 22:38:53 +02:00
|
|
|
(.format "http://{0}.tumblr.com/rss" tumblr))
|
2013-06-25 21:47:54 -04:00
|
|
|
|
|
|
|
(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)))
|
|
|
|
|
2014-09-05 21:17:46 -04:00
|
|
|
(if (cut argv 2)
|
2013-06-25 21:47:54 -04:00
|
|
|
(print-posts (get argv 2))
|
|
|
|
(print-posts "this-plt-life"))
|