Skip to content

Instantly share code, notes, and snippets.

@edbond
Created February 15, 2016 15:05
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 edbond/03f21089faf3e7923574 to your computer and use it in GitHub Desktop.
Save edbond/03f21089faf3e7923574 to your computer and use it in GitHub Desktop.
(defn make-screenshots-xf []
(fn [xf]
(let [_ (debug "Starting new browser")
browser (new-driver {:browser :chrome})]
(debug "New browser Maximize")
(maximize browser)
(fn
([]
(debug "Init")
(xf))
([result]
(debug "Finalize" result)
;; (taxi/quit browser)
(xf result))
([result input]
(debug "Called save-screenshot with input: " input)
(xf result input)
(try
(let [filename (str "details/" (first input) "/" input ".png")]
(make-parents filename)
(to browser (str "http://www.google.com/users/" input "/details"))
(taxi/wait-until browser (fn [x]
(taxi/exists? browser "table.alerts th")) 5000 0)
;; (taxi/implicit-wait browser 1000)
(take-screenshot browser :file filename)
(xf result {input :ok}))
(catch Exception e
(xf result {input e}))))))))
(defn -main [& args]
(let [from (chan)
to (chan)
xf (make-screenshots-xf)
n 64]
;; (sequence make-screenshots-xf tickers)
(prn "Starting pipeline")
(async/pipeline-blocking n to xf from)
(prn "Copy input tickers " tickers " (" (count tickers) ") onto " from)
(async/onto-chan from tickers)
(prn "Waiting for results")
(time
(let [results (async/<!! (async/into [] to))]
(pprint results (writer "results.txt"))
(prn "Results " results)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment