From 663f954410aaf0982d46c8ea124320985b042913 Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Thu, 11 Jun 2020 19:45:11 -0700 Subject: [PATCH] Updated config examples. --- config-skel.yaml | 18 +++++-- secrets-skel.yaml | 5 ++ .../advisorycircular/twitter.cljs~ | 52 +++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/main/lemondronor/advisorycircular/twitter.cljs~ diff --git a/config-skel.yaml b/config-skel.yaml index d584706..d4cf52e 100644 --- a/config-skel.yaml +++ b/config-skel.yaml @@ -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 diff --git a/secrets-skel.yaml b/secrets-skel.yaml index 1de1192..1040852 100644 --- a/secrets-skel.yaml +++ b/secrets-skel.yaml @@ -1,2 +1,7 @@ adsbx: api-key: +twitter: + consumer-key: xxx + consumer-secret: xxx + access-token: xxx + access-token-secret: xxx diff --git a/src/main/lemondronor/advisorycircular/twitter.cljs~ b/src/main/lemondronor/advisorycircular/twitter.cljs~ new file mode 100644 index 0000000..3dee483 --- /dev/null +++ b/src/main/lemondronor/advisorycircular/twitter.cljs~ @@ -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))))