Created
July 18, 2011 18:23
-
-
Save neotyk/1090238 to your computer and use it in GitHub Desktop.
twitter sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns twitter-sample | |
(:require [http.async.client :as c] | |
[org.danlarkin.json :as j])) | |
(def u "username") | |
(def p "password") | |
(defn print-user-and-text [prefix s] | |
(let [twit (j/decode-from-str s) | |
user (:screen_name (:user twit)) | |
text (:text twit)] | |
(println prefix ":" user "=>" text))) | |
;; statuses/sample | |
(defn statuses-sample [] | |
(with-open [client (c/create-client)] | |
(doseq [twit-str (c/string | |
(c/stream-seq client :get "http://stream.twitter.com/1/statuses/sample.json" | |
:auth {:user u :password p}))] | |
(print-user-and-text "sample" twit-str)))) | |
;; statuses/filter | |
(defn statuses-filter [] | |
(with-open [client (c/create-client)] | |
(doseq [twit-str (c/string | |
(c/stream-seq client :post "http://stream.twitter.com/1/statuses/filter.json" | |
:body {"track" "basketball,football,baseball,footy,soccer"} | |
:auth {:user u :password p}))] | |
(print-user-and-text "sports" twit-str)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment