-
-
Save kelseyq/51dce2e997b393f469b5 to your computer and use it in GitHub Desktop.
clojure newb code
This file contains 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
(defn intOrZero | |
[theString] | |
(try (Integer/parseInt (clojure.string/trim theString)) | |
(catch Exception e 0))) | |
(defn -main | |
[] | |
(let [expected (atom 0) | |
cnt (atom 0) | |
tweet (atom "")] | |
(defn updateWithChunk | |
[newText] | |
(do | |
(swap! cnt #(+ (count (byte-array (map byte newText))) %)) ;update count of bytes | |
(swap! tweet #(str % newText)) ;update current message) | |
)) | |
(statuses-filter :params {:track "giants", :delimited "length"} | |
:oauth-creds my-creds | |
:callbacks (SyncStreamingCallback. (fn [_resp payload] | |
(let [bodyString (.toString payload)] | |
(do | |
(if (== @expected 0) | |
(let [splitBody (clojure.string/split bodyString #"\n" 2)] | |
(do | |
(reset! expected (intOrZero (get splitBody 0)));update the expected # of bytes | |
(updateWithChunk (get splitBody (dec (count splitBody)))) | |
)) | |
(updateWithChunk bodyString) | |
) | |
(if (>= @cnt @expected) | |
(do | |
(println (extractTweetInfo (readJson @tweet))) | |
(reset! expected 0) | |
(reset! cnt 0) | |
(reset! tweet "") | |
) | |
() | |
) | |
))) | |
(comp println response-return-everything) | |
exception-print)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment