From 70474938acee14e1eb9f85b274758bb226a6d7a4 Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Mon, 2 Mar 2020 22:26:35 -0800 Subject: [PATCH] Fixed screenshots. adsbexchange.com switched from VRS to tar1090 and broke the screenshot code. --- src/main/lemondronor/circlebot/adsbx.cljs | 78 +++-------------------- 1 file changed, 8 insertions(+), 70 deletions(-) diff --git a/src/main/lemondronor/circlebot/adsbx.cljs b/src/main/lemondronor/circlebot/adsbx.cljs index 5245dfe..4751ac1 100644 --- a/src/main/lemondronor/circlebot/adsbx.cljs +++ b/src/main/lemondronor/circlebot/adsbx.cljs @@ -40,31 +40,6 @@ (/ (.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 ([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) (let [icao-selector (gstring/format "//td[contains(., '%s')]" (string/upper-case icao)) - launch-options {:headless (get options :headless? true) + launch-options {:headless (get options :headless? false) :defaultViewport (get options :viewport {:width 1600 :height 800})} took-screenshot?_ (atom false)] @@ -87,51 +62,14 @@ page (.newPage browser)] (if-let [user-agent (:user-agent options)] (.setUserAgent page user-agent)) - (if-let [vrs-settings (:vrs-settings options)] - (import-settings page vrs-settings)) (log-debug "Navigating") (p/all [(.waitForNavigation 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/"}))]) - ;; 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) + (p/all [(.type (.-keyboard page) "l") + (timeout 1000)]) (let [path (get options :output-path (str "screenshot-" (.toFixed (current-time-secs) 0) "-" @@ -140,10 +78,10 @@ (log-verbose "Writing %s" path) (p/do (.screenshot page (clj->js {:path path - :clip (get options :clip {:width 860 - :height 680 - :x 46 - :y 46})})) + :clip (get options :clip {:width 1200 + :height 800 + :x 200 + :y 0})})) (log-debug "screenshot done") (reset! took-screenshot?_ true) (log-debug "closing browser")