Renamed --url to --adsbx-url, added --pelias-url. Config cleanup.

This commit is contained in:
John Wiseman 2019-12-18 14:14:55 -08:00
parent 0f9dddacee
commit b93c2f71d4
3 changed files with 42 additions and 24 deletions

View File

@ -81,7 +81,10 @@ Compile the clojurescript:
Run the bot:
`node out/script.js --url https://adsbexchange.com/api/aircraft/json --lat <lat> --lon <lon> --radius <radius>;`
```
node out/script.js --adsbx-url https://adsbexchange.com/api/aircraft/json \
--pelias-url http://my-pelias.local:4000/v1 \
--lat <lat> --lon <lon> --radius <radius>`
Specify your geographical region of interest by specifying a circle at
`<lat>`, `<lon>` with a radius of `<radius>` 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 <lat> --lon <lon> --radius <radius>
node out/script.js --adsbx-url https://adsbexchange.com/api/aircraft/json --pelias-url http://my-pelias.local:4000/v1 --lat <lat> --lon <lon> --radius <radius>
sleep 10
done
```

View File

@ -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,12 +374,16 @@
(: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
(p/let [nearby (pelias/nearby
(:pelias config)
lat
lon
{:boundary.circle.radius 100
:layers "venue"
:size 50})
nearby (:features nearby)
@ -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 <lat>" "Latitude of the circle of region of interest" parse-number)
(.requiredOption "--lon <lat>" "Longitude of the circle of the region of interest" parse-number)
(.requiredOption "--url <url>" "API url")
(.requiredOption "--adsbx-url <url>" "ADSBX API url")
(.requiredOption "--pelias-url <url>" "Base pelias geocoder URL")
(.option "--radius <radius>" "Radius of the circle of interest, in nautical miles" 20 parse-number)
(.option "--basestation-sqb <path>" "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)

View File

@ -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)})))