-
-
Save anonymous/623164e2ffbbec86432f to your computer and use it in GitHub Desktop.
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
;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