Last active
January 3, 2016 17:39
-
-
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.
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
| (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