Updated config examples.

This commit is contained in:
John Wiseman 2020-06-11 19:45:11 -07:00
parent 960700a11d
commit 663f954410
3 changed files with 72 additions and 3 deletions

View File

@ -1,11 +1,23 @@
adsbx:
url: https://adsbexchange.com/api/aircraft/json
pelias:
url: http://lockheed.local:4000/v1
url: http://localhost:4000/v1
lat: 34.1335
lon: -118.1924
radius-km: 30
basestation-sqb: clean-basestation.sqb
radius-km: 50
landmarks:
blocklist:
- Johnny.Depp
twitter:
enabled?: true
# Look for 4 circles in an hour instead of 25 minutes:
#
#max-history-age-ms: 3600000
# The map screenshot should use aerial imagery instead of
# openstreetmap:
#
#screenshot:
# layer: esri
# zoom: 12
# simple-tracks: false

View File

@ -1,2 +1,7 @@
adsbx:
api-key: <my api key>
twitter:
consumer-key: xxx
consumer-secret: xxx
access-token: xxx
access-token-secret: xxx

View File

@ -0,0 +1,52 @@
(ns lemondronor.advisorycircular.twitter
(:require
["fs" :as fs]
[kitchen-async.promise :as p]
[lemondronor.advisorycircular.logging :as logging]
[lemondronor.advisorycircular.util :as util]
["twit" :as Twit]))
(def fsprom (.-promises fs))
(declare logger log-debug log-verbose log-info log-warn log-error)
(logging/deflog "twitter" logger)
;; Creates a new twit object.
(defn twit [config]
(Twit. (clj->js {:consumer_key (:consumer-key config)
:consumer_secret (:consumer-secret config)
:access_token (:access-token config)
:access_token_secret (:access-token-secret config)})))
;; Uploads an image to twitter. Returns a promise that resolves to the
;; new media ID of the image.
(defn upload-image [twit path]
(log-info "Uploading media to twitter: %s" path)
(p/let [b64content (util/read-file path {:encoding "base64"})
result (.post twit "media/upload" (clj->js {:media_data b64content}))
media-id (get-in (js->clj result :keywordize-keys true) [:data :media_id_string])]
(log-info "%s got media ID %s" path media-id)
media-id))
;; Posts a tweet with optional multiple media. Returns a promise that
;; resolves to the response result.
(defn tweet [twit status image-paths lat lon]
(p/then (p/all (map #(upload-image twit %) image-paths))
(fn [media-ids]
(log-warn "Tweeting status:'%s' with media: %s" status media-ids)
(p/let [result (.post twit "statuses/update"
(clj->js {:status status
:media_ids [media-ids]
:lat lat
:long lon
:display_coordinates true
}))
result (js->clj result :keywordize-keys true)]
(log-debug "Tweet posted: %s" result)
result))))