hy/eg/lxml/parse-tumblr.hy

26 lines
596 B
Hy
Raw Normal View History

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