Merge branch 'add-rapidapi-support' into 'master'
add rapidapi support Closes #30 See merge request jjwiseman/advisory-circular!5
This commit is contained in:
commit
2321468260
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,7 @@ node_modules
|
||||
out
|
||||
.DS_Store
|
||||
screenshots
|
||||
config.yaml
|
||||
secrets.yaml
|
||||
build
|
||||
advisorycircular.json
|
||||
|
@ -1,6 +1,7 @@
|
||||
(ns lemondronor.advisorycircular
|
||||
(:require
|
||||
["canvas" :as canvas]
|
||||
[cemerick.url :as c-url]
|
||||
["commander" :as commander]
|
||||
["fs" :as fs]
|
||||
["tmp-promise" :as tmp]
|
||||
@ -107,15 +108,19 @@
|
||||
(js->clj (parse-json json-str))
|
||||
"ac"))})
|
||||
|
||||
|
||||
(defn get-adsbexchange-live-data [{:keys [url lat lon radius-nm api-key api-whitelist]}]
|
||||
(let [url (->> [url
|
||||
"lat" lat
|
||||
"lon" lon
|
||||
"dist" (.toFixed radius-nm 1)]
|
||||
(map str)
|
||||
(string/join "/"))
|
||||
headers (cond-> {:api-auth api-key}
|
||||
(defn get-adsbexchange-live-data [{:keys [url lat lon radius-nm api-key api-whitelist rapid-api?]}]
|
||||
(let [url (str
|
||||
(->> [url
|
||||
"lat" lat
|
||||
"lon" lon
|
||||
"dist" (.toFixed radius-nm (if rapid-api? 0 1))]
|
||||
(map str)
|
||||
(string/join "/"))
|
||||
;; RapidAPI expects a trailing slash.
|
||||
(if rapid-api? "/" ""))
|
||||
headers (cond-> (if rapid-api?
|
||||
{:x-rapidapi-key api-key :x-rapidapi-host (:host (c-url/url url)) :useQueryString true}
|
||||
{:auth-key api-key})
|
||||
api-whitelist (assoc :ADSBX-WL api-whitelist))]
|
||||
(p/let [http-result (util/http-get url {:headers headers})]
|
||||
(let [result (parse-adsbexchange-live-data http-result)]
|
||||
@ -716,7 +721,8 @@
|
||||
:minimum-airport-distance-km 3.5
|
||||
:history-db-path "advisorycircular.json"
|
||||
:aircraft-info-db-path "aircraft-info.sqb"
|
||||
:twitter {:enabled? true}})
|
||||
:twitter {:enabled? true}
|
||||
:rapid-api? false})
|
||||
|
||||
|
||||
(defn build-config-from-commander [commander]
|
||||
@ -754,7 +760,8 @@
|
||||
[:aircraft-info-db-path]
|
||||
[:adsbx :url]
|
||||
[:adsbx :api-key]
|
||||
[:pelias :url]]
|
||||
[:pelias :url]
|
||||
[:rapid-api?]]
|
||||
present (util/nested-keys config)
|
||||
missing1 (set/difference (set required) (set present))
|
||||
missing2 (when (get-in config [:twitter :enabled?])
|
||||
@ -826,7 +833,8 @@
|
||||
(merge (:adsbx config)
|
||||
{:lat (:lat config)
|
||||
:lon (:lon config)
|
||||
:radius-nm (* (:radius-km config) 0.539957)}))
|
||||
:radius-nm (* (:radius-km config) 0.539957)
|
||||
:rapid-api? (:rapid-api? config)}))
|
||||
filtered-api-data (remove-blocked-icaos api-data (get config :icao-blocklist '()))
|
||||
now (current-time)
|
||||
[new-db potential-circles] (-> db
|
||||
|
@ -1,6 +1,7 @@
|
||||
(ns lemondronor.advisorycircular.util
|
||||
(:require [cemerick.url :as c-url]
|
||||
["fs" :as fs]
|
||||
[goog.string :as gstring]
|
||||
[kitchen-async.promise :as p]
|
||||
[lemondronor.advisorycircular.logging :as logging]
|
||||
["request-promise-native" :as request]
|
||||
@ -11,6 +12,9 @@
|
||||
|
||||
(def fs-promises (.-promises fs))
|
||||
|
||||
(defn ^boolean ends-with?
|
||||
[s substr]
|
||||
(gstring/endsWith s substr))
|
||||
|
||||
;; Reads a file, returns a promise resolving to the file contents.
|
||||
|
||||
@ -51,8 +55,13 @@
|
||||
([url options]
|
||||
(let [query (or (:query options) {})
|
||||
options (dissoc options :query)
|
||||
url (-> (c-url/url (str url))
|
||||
(assoc :query query))]
|
||||
parsed-url (-> (c-url/url (str url))
|
||||
(assoc :query query))
|
||||
;; Work around c-url bug to re-append any stripped trailing slash.
|
||||
;; https://github.com/cemerick/url/issues/24
|
||||
url (if (ends-with? (str url) "/")
|
||||
(str parsed-url "/")
|
||||
parsed-url)]
|
||||
(p/do
|
||||
(log-verbose "Fetching %s" url)
|
||||
(p/let [result (.get request
|
||||
|
Loading…
Reference in New Issue
Block a user