Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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