Fixed screenshots.
adsbexchange.com switched from VRS to tar1090 and broke the screenshot code.
This commit is contained in:
parent
567cf8a4f9
commit
70474938ac
@ -40,31 +40,6 @@
|
|||||||
(/ (.getTime (js/Date.)) 1000))
|
(/ (.getTime (js/Date.)) 1000))
|
||||||
|
|
||||||
|
|
||||||
(defn import-settings [page settings]
|
|
||||||
(let [import-settings-btn-xpath "//button[contains(text(), 'Import Settings')]"]
|
|
||||||
(p/try
|
|
||||||
(log-debug "Importing settings")
|
|
||||||
(p/all [(.waitForNavigation page)
|
|
||||||
(.waitForXPath page import-settings-btn-xpath)
|
|
||||||
(.goto page
|
|
||||||
"https://global.adsbexchange.com/VirtualRadar/settings.html"
|
|
||||||
(clj->js {:referer "https://adsbexchange.com/"}))])
|
|
||||||
(timeout 50)
|
|
||||||
(p/let [import-settings-btn (.$x page import-settings-btn-xpath)]
|
|
||||||
(.click (nth import-settings-btn 0))
|
|
||||||
(.waitForSelector page "textarea")
|
|
||||||
(p/let [textarea (.$x page "//textarea")]
|
|
||||||
(.evaluate page
|
|
||||||
(fn [el value]
|
|
||||||
(set! (.-value el) value))
|
|
||||||
(nth textarea 0)
|
|
||||||
settings))
|
|
||||||
(p/let [import-btn (.$x page "//button[text()='Import']")]
|
|
||||||
(.click (nth import-btn 0))
|
|
||||||
(timeout 100)))
|
|
||||||
(log-debug "Imported settings"))))
|
|
||||||
|
|
||||||
|
|
||||||
(defn screenshot-aircraft
|
(defn screenshot-aircraft
|
||||||
([icao lat lon]
|
([icao lat lon]
|
||||||
(screenshot-aircraft icao lat lon {}))
|
(screenshot-aircraft icao lat lon {}))
|
||||||
@ -72,7 +47,7 @@
|
|||||||
(log-info "Taking screenshot of aircraft %s at %s %s" icao lat lon)
|
(log-info "Taking screenshot of aircraft %s at %s %s" icao lat lon)
|
||||||
(let [icao-selector (gstring/format "//td[contains(., '%s')]"
|
(let [icao-selector (gstring/format "//td[contains(., '%s')]"
|
||||||
(string/upper-case icao))
|
(string/upper-case icao))
|
||||||
launch-options {:headless (get options :headless? true)
|
launch-options {:headless (get options :headless? false)
|
||||||
:defaultViewport (get options :viewport {:width 1600
|
:defaultViewport (get options :viewport {:width 1600
|
||||||
:height 800})}
|
:height 800})}
|
||||||
took-screenshot?_ (atom false)]
|
took-screenshot?_ (atom false)]
|
||||||
@ -87,51 +62,14 @@
|
|||||||
page (.newPage browser)]
|
page (.newPage browser)]
|
||||||
(if-let [user-agent (:user-agent options)]
|
(if-let [user-agent (:user-agent options)]
|
||||||
(.setUserAgent page user-agent))
|
(.setUserAgent page user-agent))
|
||||||
(if-let [vrs-settings (:vrs-settings options)]
|
|
||||||
(import-settings page vrs-settings))
|
|
||||||
(log-debug "Navigating")
|
(log-debug "Navigating")
|
||||||
(p/all [(.waitForNavigation page)
|
(p/all [(.waitForNavigation page)
|
||||||
(.goto page
|
(.goto page
|
||||||
"https://global.adsbexchange.com/VirtualRadar/desktop.html"
|
(gstring/format "https://tar1090.adsbexchange.com/?icao=%s&noIsolation&hideButtons&hideSidebar&monochromeMarkers=ffff55&monochromeTracks=010101&outlineColor=505050&zoom=14" icao)
|
||||||
(clj->js {:referer "https://adsbexchange.com/"}))])
|
(clj->js {:referer "https://adsbexchange.com/"}))])
|
||||||
;; Wait until the page has loaded the pan and zoom functions
|
|
||||||
;; we need.
|
|
||||||
(log-debug "Waiting for script objects")
|
|
||||||
(.waitForFunction page "window.VRS")
|
|
||||||
(.waitForFunction page "VRS.bootstrap")
|
|
||||||
(.waitForFunction page "VRS.bootstrap.pageSettings")
|
|
||||||
(.waitForFunction page "VRS.bootstrap.pageSettings.mapPlugin")
|
|
||||||
(log-debug "Xooming")
|
|
||||||
;; Zoom.
|
|
||||||
(.evaluate
|
|
||||||
page
|
|
||||||
(gstring/format "VRS.bootstrap.pageSettings.mapPlugin.setZoom(%s);" (get options :zoom 13)))
|
|
||||||
(timeout 500)
|
|
||||||
;; Pan to the coordinates of interest.
|
|
||||||
(log-debug "Panning")
|
|
||||||
(.evaluate
|
|
||||||
page
|
|
||||||
(gstring/format
|
|
||||||
"VRS.bootstrap.pageSettings.mapPlugin.panTo({lat:%f,lng:%f});"
|
|
||||||
lat
|
|
||||||
lon))
|
|
||||||
;; Once we pan to our area of interest it can take some time
|
|
||||||
;; for VRS to load in the map tiles and the aircraft present
|
|
||||||
;; in that area. So we wait before clicking.
|
|
||||||
(log-debug "Waiting for aircraft")
|
|
||||||
(.waitForXPath page icao-selector)
|
|
||||||
;; Now try to click on the aircraft of interest in the list
|
|
||||||
;; display.
|
|
||||||
(log-debug "Selecting aircraft")
|
|
||||||
(p/let [aircraft-entry (.$x page icao-selector)]
|
|
||||||
(.click (nth aircraft-entry 0)))
|
|
||||||
;; Click "Show on map" to center it.
|
|
||||||
(p/let [show-on-map (.$x page "//a[contains(., 'Show on map')]")]
|
|
||||||
(.click (nth show-on-map 0)))
|
|
||||||
;; Wait for tiles to load. I wonder if we could try something
|
|
||||||
;; like this:
|
|
||||||
;; https://stackoverflow.com/questions/22288933/how-to-tell-when-all-visible-tiles-have-fully-loaded
|
|
||||||
(timeout 3000)
|
(timeout 3000)
|
||||||
|
(p/all [(.type (.-keyboard page) "l")
|
||||||
|
(timeout 1000)])
|
||||||
(let [path (get options :output-path (str "screenshot-"
|
(let [path (get options :output-path (str "screenshot-"
|
||||||
(.toFixed (current-time-secs) 0)
|
(.toFixed (current-time-secs) 0)
|
||||||
"-"
|
"-"
|
||||||
@ -140,10 +78,10 @@
|
|||||||
(log-verbose "Writing %s" path)
|
(log-verbose "Writing %s" path)
|
||||||
(p/do
|
(p/do
|
||||||
(.screenshot page (clj->js {:path path
|
(.screenshot page (clj->js {:path path
|
||||||
:clip (get options :clip {:width 860
|
:clip (get options :clip {:width 1200
|
||||||
:height 680
|
:height 800
|
||||||
:x 46
|
:x 200
|
||||||
:y 46})}))
|
:y 0})}))
|
||||||
(log-debug "screenshot done")
|
(log-debug "screenshot done")
|
||||||
(reset! took-screenshot?_ true)
|
(reset! took-screenshot?_ true)
|
||||||
(log-debug "closing browser")
|
(log-debug "closing browser")
|
||||||
|
Loading…
Reference in New Issue
Block a user