Added --stats which (for now) just prints the number of twitter followers.
Refactored config handling a bit.
This commit is contained in:
parent
0f07b705c1
commit
c3c384d030
@ -779,6 +779,41 @@
|
|||||||
(def default-config-path "config.yaml")
|
(def default-config-path "config.yaml")
|
||||||
|
|
||||||
|
|
||||||
|
(defn get-config
|
||||||
|
([commander]
|
||||||
|
(get-config commander {}))
|
||||||
|
([commander options]
|
||||||
|
(p/let [base-config (if-let [config-path (.-config commander)]
|
||||||
|
(util/read-config config-path)
|
||||||
|
(if (fs/existsSync default-config-path)
|
||||||
|
(util/read-config default-config-path)
|
||||||
|
{}))
|
||||||
|
cli-config (build-config-from-commander commander)
|
||||||
|
secrets (if (:no-secrets? options)
|
||||||
|
{}
|
||||||
|
(util/read-config (.-secrets commander)))
|
||||||
|
config (build-config base-config cli-config secrets)
|
||||||
|
_ (if (:no-validate? options)
|
||||||
|
nil
|
||||||
|
(validate-config config))]
|
||||||
|
config)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn get-stats [config]
|
||||||
|
(let [twit (twitter/twit (:twitter config))]
|
||||||
|
(p/let [followers (.get twit "followers/ids")
|
||||||
|
num-followers (-> followers
|
||||||
|
(js->clj :keywordize-keys true)
|
||||||
|
:data
|
||||||
|
:ids
|
||||||
|
count)]
|
||||||
|
{:num-followers num-followers})))
|
||||||
|
|
||||||
|
|
||||||
|
(defn print-stats [stats]
|
||||||
|
(println (:num-followers stats) "Twitter followers"))
|
||||||
|
|
||||||
|
|
||||||
(defn main [& args]
|
(defn main [& args]
|
||||||
(-> commander
|
(-> commander
|
||||||
(.option "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
|
(.option "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
|
||||||
@ -795,6 +830,7 @@
|
|||||||
(.option "--log-prefix <prefix>" "Log prefix to use")
|
(.option "--log-prefix <prefix>" "Log prefix to use")
|
||||||
(.option "--airport-geojson" "Generate airport GEOJSON and exit")
|
(.option "--airport-geojson" "Generate airport GEOJSON and exit")
|
||||||
(.option "--create-aircraft-info-db-from-json <json path>" "Generate aircraft info DB and exit")
|
(.option "--create-aircraft-info-db-from-json <json path>" "Generate aircraft info DB and exit")
|
||||||
|
(.option "--stats" "Show bot stats and exit")
|
||||||
(.parse (.-argv js/process)))
|
(.parse (.-argv js/process)))
|
||||||
(logging/set-log-prefix! (or (.-logPrefix commander) ""))
|
(logging/set-log-prefix! (or (.-logPrefix commander) ""))
|
||||||
(reset! log-prefix (or (.-logPrefix commander) ""))
|
(reset! log-prefix (or (.-logPrefix commander) ""))
|
||||||
@ -803,28 +839,18 @@
|
|||||||
(.-createAircraftInfoDbFromJson commander)
|
(.-createAircraftInfoDbFromJson commander)
|
||||||
(create-aircraft-info-db (.-createAircraftInfoDbFromJson commander) (.-aircraftInfoDb commander))
|
(create-aircraft-info-db (.-createAircraftInfoDbFromJson commander) (.-aircraftInfoDb commander))
|
||||||
(.-airportGeojson commander)
|
(.-airportGeojson commander)
|
||||||
(p/let [base-config (if-let [config-path (.-config commander)]
|
(p/let [config (get-config commander {:no-secrets? true :no-validate? true})
|
||||||
(util/read-config config-path)
|
|
||||||
(if (fs/existsSync default-config-path)
|
|
||||||
(util/read-config default-config-path)
|
|
||||||
{}))
|
|
||||||
cli-config (build-config-from-commander commander)
|
|
||||||
config (build-config base-config cli-config {})
|
|
||||||
geojson (airport-geojson config)]
|
geojson (airport-geojson config)]
|
||||||
(println (.stringify js/JSON (clj->js geojson) nil " ")))
|
(println (.stringify js/JSON (clj->js geojson) nil " ")))
|
||||||
|
(.-stats commander)
|
||||||
|
(p/let [config (get-config commander)
|
||||||
|
stats (get-stats config)]
|
||||||
|
(print-stats stats))
|
||||||
:else
|
:else
|
||||||
(let [start-time (current-time)]
|
(let [start-time (current-time)]
|
||||||
;; If --config-path is specified, definitely try to read that
|
;; If --config-path is specified, definitely try to read that
|
||||||
;; file. Otherwise, only read config.yaml if it exists.
|
;; file. Otherwise, only read config.yaml if it exists.
|
||||||
(p/let [base-config (if-let [config-path (.-config commander)]
|
(p/let [config (get-config commander)
|
||||||
(util/read-config config-path)
|
|
||||||
(if (fs/existsSync default-config-path)
|
|
||||||
(util/read-config default-config-path)
|
|
||||||
{}))
|
|
||||||
cli-config (build-config-from-commander commander)
|
|
||||||
secrets (util/read-config (.-secrets commander))
|
|
||||||
config (build-config base-config cli-config secrets)
|
|
||||||
_ (validate-config config)
|
|
||||||
history-db-path (:history-db-path config)
|
history-db-path (:history-db-path config)
|
||||||
_ (when (not (fs/existsSync history-db-path))
|
_ (when (not (fs/existsSync history-db-path))
|
||||||
(log-info "%s does not exist; creating empty one." history-db-path)
|
(log-info "%s does not exist; creating empty one." history-db-path)
|
||||||
|
Loading…
Reference in New Issue
Block a user