-
Notifications
You must be signed in to change notification settings - Fork 1
/
etaoin.clj
32 lines (27 loc) · 1.04 KB
/
etaoin.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns is.simm.runtimes.etaoin
"Headless browser control.
Languages: browser
Properties: substrate"
(:require [etaoin.api :as e]
[clojure.core.async :refer [chan pub sub mult tap]]
[superv.async :refer [S go-loop-try <? put?]]))
(defn extract-body [url]
(e/with-firefox-headless driver
(e/go driver url)
(e/get-element-text driver {:tag :body})))
(defn etaoin [[S peer [in out]]]
(let [mi (mult in)
next-in (chan)
_ (tap mi next-in)
pub-in (chan)
_ (tap mi pub-in)
pi (pub pub-in :type)
get-body (chan)
_ (sub pi :is.simm.languages.browser/extract-body get-body)]
(go-loop-try S [{[url] :args :as s} (<? S get-body)]
(when s
(put? S out (assoc s
:type :is.simm.languages.browser/extract-body-reply
:response (try (extract-body url) (catch Exception e e))))
(recur (<? S get-body))))
[S peer [next-in out]]))