Skip to content

Instantly share code, notes, and snippets.

@diogok
Created March 16, 2010 03:06
Show Gist options
  • Save diogok/333594 to your computer and use it in GitHub Desktop.
Save diogok/333594 to your computer and use it in GitHub Desktop.
(ns twitter-search
(:require [clojure.contrib.json.read :as json])
(:require [clojure.contrib.http.agent :as http ])
(:import (java.net URL URLEncoder))
)
(defn search [word last-id]
(let [term (URLEncoder/encode word "UTF-8")
result (http/string (http/http-agent (str
"http://search.twitter.com/search.json?q="
word "&since-id=" @last-id "&rpp=50")))]
(do
(send last-id (fn [a] (get (json/read-json result) "max_id")))
(reduce (fn [t0 t1] (str t0 "\n" t1))
(reverse (map
(fn [tweet]
(str "@" (get tweet "from_user") " : " (get tweet "text")))
(get (json/read-json result) "results")
)))
)
))
(defn -main [word]
(while true
(let [last-id (agent 0)]
(do (println (search word last-id))
(java.lang.Thread/sleep 15000)
))))
(-main "diogok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment