forked from cch1/http.async.client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter-sample.clj
31 lines (26 loc) · 1.12 KB
/
twitter-sample.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns twitter-sample
(:require [http.async.client :as c]
[org.danlarkin.json :as j]))
;; Please consider using https://github.com/adamwynne/twitter-api
(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))))