Renamed --url to --adsbx-url, added --pelias-url. Config cleanup.
This commit is contained in:
parent
0f9dddacee
commit
b93c2f71d4
@ -81,7 +81,10 @@ Compile the clojurescript:
|
|||||||
|
|
||||||
Run the bot:
|
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
|
Specify your geographical region of interest by specifying a circle at
|
||||||
`<lat>`, `<lon>` with a radius of `<radius>` miles.
|
`<lat>`, `<lon>` with a radius of `<radius>` miles.
|
||||||
@ -93,7 +96,7 @@ collect some history before it's able to detect any circles.
|
|||||||
```
|
```
|
||||||
while :
|
while :
|
||||||
do
|
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
|
sleep 10
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
@ -254,8 +254,9 @@
|
|||||||
x)
|
x)
|
||||||
|
|
||||||
|
|
||||||
(defn closest-airport [lat lon]
|
(defn closest-airport [config lat lon]
|
||||||
(p/let [results (pelias/nearby lat lon
|
(p/let [results (pelias/nearby (:pelias config)
|
||||||
|
lat lon
|
||||||
{:categories "transport:air:aerodrome"
|
{:categories "transport:air:aerodrome"
|
||||||
:boundary.circle.radius 7})]
|
:boundary.circle.radius 7})]
|
||||||
(-> results
|
(-> results
|
||||||
@ -359,7 +360,7 @@
|
|||||||
lat (:lat centroid)
|
lat (:lat centroid)
|
||||||
lon (:lon centroid)
|
lon (:lon centroid)
|
||||||
_ (log-info "%s: Recent centroid: %s %s" icao lat lon)
|
_ (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)]
|
airport-properties (:properties airport)]
|
||||||
(if airport
|
(if airport
|
||||||
(log-info "%s: Closest airport is %s, distance: %s km"
|
(log-info "%s: Closest airport is %s, distance: %s km"
|
||||||
@ -373,12 +374,16 @@
|
|||||||
(:label airport-properties)
|
(:label airport-properties)
|
||||||
())
|
())
|
||||||
(do
|
(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))]
|
(let [coarse (first (:features coarse))]
|
||||||
(log-info "%s: Reverse geocode: %s" icao (:properties coarse))
|
(log-info "%s: Reverse geocode: %s" icao (:properties coarse))
|
||||||
;; Note that if we're over the ocean we get null :(
|
;; Note that if we're over the ocean we get null :(
|
||||||
(p/then (p/all [(screenshot (:icao ac) lat lon)
|
(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"
|
:layers "venue"
|
||||||
:size 50})
|
:size 50})
|
||||||
nearby (:features nearby)
|
nearby (:features nearby)
|
||||||
@ -409,7 +414,7 @@
|
|||||||
(= (get-in coarse [:properties :name]) "California"))
|
(= (get-in coarse [:properties :name]) "California"))
|
||||||
(log-info "%s: Filtering out because it is outside Los Angeles County" (:icao ac))
|
(log-info "%s: Filtering out because it is outside Los Angeles County" (:icao ac))
|
||||||
(if (and image-path description)
|
(if (and image-path description)
|
||||||
(if (and (:tweeting-enabled? config) (:twitter config))
|
(if (get-in config [:twitter :enabled?])
|
||||||
(twitter/tweet (twitter/twit (:twitter config))
|
(twitter/tweet (twitter/twit (:twitter config))
|
||||||
description
|
description
|
||||||
[image-path])
|
[image-path])
|
||||||
@ -429,11 +434,23 @@
|
|||||||
(def secrets-path "secrets.yaml")
|
(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]
|
(defn main [& args]
|
||||||
(-> commander
|
(-> commander
|
||||||
(.requiredOption "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
|
(.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 "--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 "--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 "--basestation-sqb <path>" "Path to a basestation.sqb database file")
|
||||||
(.option "--no-tweeting" "Do not tweet.")
|
(.option "--no-tweeting" "Do not tweet.")
|
||||||
@ -441,16 +458,14 @@
|
|||||||
(let [start-time (current-time)]
|
(let [start-time (current-time)]
|
||||||
(p/then (p/all [(read-history-db history-db-path)
|
(p/then (p/all [(read-history-db history-db-path)
|
||||||
(util/read-config secrets-path)])
|
(util/read-config secrets-path)])
|
||||||
(fn [[db config]]
|
(fn [[db secrets]]
|
||||||
(p/let [config (assoc config
|
(p/let [config (build-config secrets commander)
|
||||||
:tweeting-enabled? (.-tweeting commander)
|
|
||||||
:basestation-sqb (.-basestationSqb commander))
|
|
||||||
data (get-adsbexchange-live-data
|
data (get-adsbexchange-live-data
|
||||||
{:url (.-url commander)
|
{:url (get-in config [:adsbx :url])
|
||||||
:api-key (get-in config [:adsbx :api-key])
|
:api-key (get-in config [:adsbx :api-key])
|
||||||
:lat (.-lat commander)
|
:lat (:lat config)
|
||||||
:lon (.-lon commander)
|
:lon (:lon config)
|
||||||
:radius-nm (.-radius commander)})
|
:radius-nm (:radius-nm config)})
|
||||||
now (current-time)
|
now (current-time)
|
||||||
[new-db potential-circles] (-> db
|
[new-db potential-circles] (-> db
|
||||||
(update-history-db (:aircraft data) now)
|
(update-history-db (:aircraft data) now)
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
(logging/deflog "pelias" logger)
|
(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
|
;; Does an HTTP GET to a pelias API url. Returns a promise that
|
||||||
@ -27,9 +27,9 @@
|
|||||||
;; to the query results.
|
;; to the query results.
|
||||||
|
|
||||||
(defn nearby
|
(defn nearby
|
||||||
([lat lon options]
|
([config lat lon options]
|
||||||
(log-verbose "Performing nearby query %s %s %s" 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
|
{:query (assoc options
|
||||||
:point.lat lat
|
:point.lat lat
|
||||||
:point.lon lon)})))
|
:point.lon lon)})))
|
||||||
@ -39,9 +39,9 @@
|
|||||||
;; to the query result.
|
;; to the query result.
|
||||||
|
|
||||||
(defn reverse
|
(defn reverse
|
||||||
([lat lon options]
|
([config lat lon options]
|
||||||
(log-verbose "Performing reverse query %s %s %s" 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
|
{:query (assoc options
|
||||||
:point.lat lat
|
:point.lat lat
|
||||||
:point.lon lon)})))
|
:point.lon lon)})))
|
||||||
|
Loading…
Reference in New Issue
Block a user