[bknr-cvs] hans changed trunk/projects/planetwit/planetwit.clj
BKNR Commits
bknr at bknr.net
Wed Aug 19 19:50:49 UTC 2009
Revision: 4442
Author: hans
URL: http://bknr.net/trac/changeset/4442
[] is not nil
U trunk/projects/planetwit/planetwit.clj
Modified: trunk/projects/planetwit/planetwit.clj
===================================================================
--- trunk/projects/planetwit/planetwit.clj 2009-08-19 18:11:37 UTC (rev 4441)
+++ trunk/projects/planetwit/planetwit.clj 2009-08-19 19:50:49 UTC (rev 4442)
@@ -4,9 +4,12 @@
(:use clojure.contrib.duck-streams
clojure.contrib.zip-filter.xml))
-(def +state-file+ "/home/hans/clojure/planetwit/planetwit.dat")
+(defn absolute-pathname [filename]
+ (. (java.io.File. filename) getAbsolutePath))
+
+(def +state-file+ (absolute-pathname "planetwit.dat"))
(def +twitter-url+ "http://twitter.com/statuses/update.xml")
-(def +twitter-auth-file+ "/home/hans/clojure/planetwit/planetwit-auth.dat")
+(def +twitter-auth-file+ (absolute-pathname "planetwit-auth.dat"))
(defn read-file [file-name & defaults]
(try
@@ -41,30 +44,37 @@
(defn post-twits [items]
(when items
- (update-twitter-status (format "%s %s" (:title (first items))
- (:body (http/simple-http-request
- (format "http://tinyurl.com/api-create.php?url=%s"
- (:guid (first items)))
- nil))))
- (recur (rest items))))
+ (let [item (first items)]
+ (update-twitter-status
+ (format "%s %s"
+ (:title item)
+ (:body (http/simple-http-request
+ (format "http://tinyurl.com/api-create.php?url=%s"
+ (:guid item))
+ nil))))
+ (recur (rest items)))))
(defn poll
"Poll planet lisp, check for new postings, update Twitter status when new postings have appeared"
[]
(save-data
(let [old-urls (load-data)
- process
- (fn [items new-items]
- (if items
- (let [item (first items)
- guid (first (xml-> item :guid text))
- title (first (xml-> item :title text))]
- (recur (rest items)
- (if (old-urls guid)
- new-items
- (conj new-items { :guid guid :title title }))))
- (do
- (post-twits new-items)
- (map #((:guid %)) new-items))))]
- (process (xml-> (feed-to-zip "http://planet.lisp.org/rss20.xml") :channel :item)
- []))))
+ process (fn [items all-items new-items]
+ (if items
+ (let [item (first items)
+ guid (:guid item)
+ title (:title item)]
+ (recur (rest items)
+ (conj all-items item)
+ (if (old-urls guid)
+ new-items
+ (conj new-items item))))
+ (do
+ (post-twits new-items)
+ (into #{} (map #(:guid %) all-items)))))]
+ (process (map (fn [item]
+ {:guid (first (xml-> item :guid text))
+ :title (first (xml-> item :title text))})
+ (xml-> (feed-to-zip "http://planet.lisp.org/rss20.xml")
+ :channel :item))
+ nil nil))))
More information about the Bknr-cvs
mailing list