Skip to content

Instantly share code, notes, and snippets.

/asdf.clj Secret

Created August 10, 2015 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/623164e2ffbbec86432f to your computer and use it in GitHub Desktop.
Save anonymous/623164e2ffbbec86432f to your computer and use it in GitHub Desktop.
;I have a script which makes a web request, then processes the response. I want to archive
;every web request to disk, so if I want new information in the future, I can retroactively process all the requests and catch up
(require '[clj-time.core :as t]
'[clj-time.format :as f]
'[clj-http.client :as client]
'[clojure.core.async :as a])
(defn time-string []
(f/unparse
(f/formatters :basic-date-time-no-ms)
(t/now)))
(defn generate-filename []
(str "resources/" (time-string) ".edn"))
;;this creates a file with the timestamp of the data then returns it
(defn make-file! [response]
(spit (generate-filename) response)
response)
(def mk-file-xf (map make-file!))
(def c (a/chan 5 mk-file-xf))
(defn make-request []
(client/get "http://httpbin.org/get"))
(dotimes [n 5]
(a/put! c (make-request))
(Thread/sleep 1000))
; now the processing i do will take! from c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment