[bknr-cvs] hans changed trunk/projects/planetwit/planetwit.clj

BKNR Commits bknr at bknr.net
Wed Aug 19 18:11:37 UTC 2009


Revision: 4441
Author: hans
URL: http://bknr.net/trac/changeset/4441

store guid/url and title in a hash instead of in separate lists
U   trunk/projects/planetwit/planetwit.clj

Modified: trunk/projects/planetwit/planetwit.clj
===================================================================
--- trunk/projects/planetwit/planetwit.clj	2009-08-19 17:36:33 UTC (rev 4440)
+++ trunk/projects/planetwit/planetwit.clj	2009-08-19 18:11:37 UTC (rev 4441)
@@ -39,14 +39,14 @@
    (catch java.io.FileNotFoundException _
      (println (format "could not update twitter status (no auth file):\n%s\n" status)))))
 
-(defn post-twits [urls titles]
-  (when titles
-    (update-twitter-status (format "%s %s" (first titles)
+(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"
-                                                   (first urls))
+                                                   (:guid (first items)))
                                            nil))))
-    (recur (rest urls) (rest titles))))
+    (recur (rest items))))
 
 (defn poll
   "Poll planet lisp, check for new postings, update Twitter status when new postings have appeared"
@@ -54,17 +54,17 @@
   (save-data
    (let [old-urls (load-data)
          process
-         (fn [items new-urls new-titles]
+         (fn [items new-items]
            (if items
              (let [item (first items)
-                   guid (first (xml-> item :guid text)) ]
+                   guid (first (xml-> item :guid text))
+                   title (first (xml-> item :title text))]
                (recur (rest items)
-                      (conj new-urls guid)
                       (if (old-urls guid)
-                        new-titles
-                        (conj new-titles (first (xml-> item :title text))))))
+                        new-items
+                        (conj new-items { :guid guid :title title }))))
              (do
-               (post-twits new-urls new-titles)
-               new-urls)))]
+               (post-twits new-items)
+               (map #((:guid %)) new-items))))]
      (process (xml-> (feed-to-zip "http://planet.lisp.org/rss20.xml") :channel :item)
-              #{} []))))
+              []))))





More information about the Bknr-cvs mailing list