Skip to content

Instantly share code, notes, and snippets.

@amontalenti
Last active January 3, 2016 17:39
Show Gist options
  • Select an option

  • Save amontalenti/8496733 to your computer and use it in GitHub Desktop.

Select an option

Save amontalenti/8496733 to your computer and use it in GitHub Desktop.
reading tweets from a file using Clojure I/O, string utilities, and clojure.data.json.
(use 'clojure.java.io)
(use '[clojure.string :only (split)])
(require '[clojure.data.json :as json])
(defn read-tweets []
;; this opens a file
(with-open [rdr (reader "data/tweets.log")]
;; this returns a lazy-seq, which is bad since file is opened first?
;; results in IOException Stream closed
(for [line (line-seq rdr)]
(let [[apikey timestamp entry] (split line #"\|" 3)]
(vec [apikey timestamp (json/read-str entry)])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment