diff --git a/README.md b/README.md index 865da03..04bebc9 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,10 @@ Compile the clojurescript: Run the bot: -`node out/script.js --url https://adsbexchange.com/api/aircraft/json --lat --lon --radius ;` +``` +node out/script.js --adsbx-url https://adsbexchange.com/api/aircraft/json \ + --pelias-url http://my-pelias.local:4000/v1 \ + --lat --lon --radius ` Specify your geographical region of interest by specifying a circle at ``, `` with a radius of `` miles. @@ -93,7 +96,7 @@ collect some history before it's able to detect any circles. ``` while : do - node out/script.js --url https://adsbexchange.com/api/aircraft/json --lat --lon --radius + node out/script.js --adsbx-url https://adsbexchange.com/api/aircraft/json --pelias-url http://my-pelias.local:4000/v1 --lat --lon --radius sleep 10 done ``` diff --git a/src/main/lemondronor/circlebot.cljs b/src/main/lemondronor/circlebot.cljs index 9ce26e4..75651cd 100644 --- a/src/main/lemondronor/circlebot.cljs +++ b/src/main/lemondronor/circlebot.cljs @@ -254,8 +254,9 @@ x) -(defn closest-airport [lat lon] - (p/let [results (pelias/nearby lat lon +(defn closest-airport [config lat lon] + (p/let [results (pelias/nearby (:pelias config) + lat lon {:categories "transport:air:aerodrome" :boundary.circle.radius 7})] (-> results @@ -359,7 +360,7 @@ lat (:lat centroid) lon (:lon centroid) _ (log-info "%s: Recent centroid: %s %s" icao lat lon) - airport (closest-airport lat lon) + airport (closest-airport config lat lon) airport-properties (:properties airport)] (if airport (log-info "%s: Closest airport is %s, distance: %s km" @@ -373,14 +374,18 @@ (:label airport-properties) ()) (do - (p/let [coarse (pelias/reverse lat lon {:layers "coarse"})] + (p/let [coarse (pelias/reverse (:pelias config) lat lon {:layers "coarse"})] (let [coarse (first (:features coarse))] (log-info "%s: Reverse geocode: %s" icao (:properties coarse)) ;; Note that if we're over the ocean we get null :( (p/then (p/all [(screenshot (:icao ac) lat lon) - (p/let [nearby (pelias/nearby lat lon {:boundary.circle.radius 100 - :layers "venue" - :size 50}) + (p/let [nearby (pelias/nearby + (:pelias config) + lat + lon + {:boundary.circle.radius 100 + :layers "venue" + :size 50}) nearby (:features nearby) wiki-nearby (filter feature-has-wikipedia-page? nearby) sqb (if-let [sqb-path (:basestation-sqb config)] @@ -409,7 +414,7 @@ (= (get-in coarse [:properties :name]) "California")) (log-info "%s: Filtering out because it is outside Los Angeles County" (:icao ac)) (if (and image-path description) - (if (and (:tweeting-enabled? config) (:twitter config)) + (if (get-in config [:twitter :enabled?]) (twitter/tweet (twitter/twit (:twitter config)) description [image-path]) @@ -429,11 +434,23 @@ (def secrets-path "secrets.yaml") +(defn build-config [secrets commander] + (-> (merge-with merge + secrets + {:adsbx {:url (.-adsbxUrl commander)}} + {:twitter {:enabled? (.-tweeting commander)}} + {:pelias {:url (.-peliasUrl commander)}}) + (assoc :basestation-sqb (.-basestationSqb commander) + :lat (.-lat commander) + :lon (.-lon commander) + :radius-nm (.-radius commander)))) + (defn main [& args] (-> commander (.requiredOption "--lat " "Latitude of the circle of region of interest" parse-number) (.requiredOption "--lon " "Longitude of the circle of the region of interest" parse-number) - (.requiredOption "--url " "API url") + (.requiredOption "--adsbx-url " "ADSBX API url") + (.requiredOption "--pelias-url " "Base pelias geocoder URL") (.option "--radius " "Radius of the circle of interest, in nautical miles" 20 parse-number) (.option "--basestation-sqb " "Path to a basestation.sqb database file") (.option "--no-tweeting" "Do not tweet.") @@ -441,16 +458,14 @@ (let [start-time (current-time)] (p/then (p/all [(read-history-db history-db-path) (util/read-config secrets-path)]) - (fn [[db config]] - (p/let [config (assoc config - :tweeting-enabled? (.-tweeting commander) - :basestation-sqb (.-basestationSqb commander)) + (fn [[db secrets]] + (p/let [config (build-config secrets commander) data (get-adsbexchange-live-data - {:url (.-url commander) + {:url (get-in config [:adsbx :url]) :api-key (get-in config [:adsbx :api-key]) - :lat (.-lat commander) - :lon (.-lon commander) - :radius-nm (.-radius commander)}) + :lat (:lat config) + :lon (:lon config) + :radius-nm (:radius-nm config)}) now (current-time) [new-db potential-circles] (-> db (update-history-db (:aircraft data) now) diff --git a/src/main/lemondronor/circlebot/pelias.cljs b/src/main/lemondronor/circlebot/pelias.cljs index b809c3c..641b8b1 100644 --- a/src/main/lemondronor/circlebot/pelias.cljs +++ b/src/main/lemondronor/circlebot/pelias.cljs @@ -11,7 +11,7 @@ (logging/deflog "pelias" logger) - (def base-pelias-url "http://lockheed.local:4000/v1") +(def base-pelias-url "http://lockheed.local:4000/v1") ;; Does an HTTP GET to a pelias API url. Returns a promise that @@ -27,9 +27,9 @@ ;; to the query results. (defn nearby - ([lat lon options] + ([config lat lon options] (log-verbose "Performing nearby query %s %s %s" lat lon options) - (pelias-get base-pelias-url "nearby" + (pelias-get (:url config) "nearby" {:query (assoc options :point.lat lat :point.lon lon)}))) @@ -39,9 +39,9 @@ ;; to the query result. (defn reverse - ([lat lon options] + ([config lat lon options] (log-verbose "Performing reverse query %s %s %s" lat lon options) - (pelias-get base-pelias-url "reverse" + (pelias-get (:url config) "reverse" {:query (assoc options :point.lat lat :point.lon lon)})))