first step toward transformations

master
jem 4 years ago
parent 7fa26afde8
commit 21c908ea85

@ -32,13 +32,7 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
{:consumer_key "XXXX" {:consumer_key "XXXX"
:consumer_secret "XXXX" :consumer_secret "XXXX"
:access_token_key "XXXX" :access_token_key "XXXX"
:access_token_secret "XXXX"} :access_token_secret "XXXX"}}
;; optional, defaults to false
:include-replies? false
;; optional, defaults to false
:include-rts? false
;; accounts you wish to mirror
:accounts ["arstechnica" "WIRED"]}
;; add Tumblr config to mirror Tumblr accounts ;; add Tumblr config to mirror Tumblr accounts
:tumblr {:access-keys :tumblr {:access-keys
{:consumer_key "XXXX" {:consumer_key "XXXX"
@ -81,7 +75,16 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w
;; any posts not matching the regexes will be filtered out ;; any posts not matching the regexes will be filtered out
:keyword-filters [".*clojure.*"] :keyword-filters [".*clojure.*"]
;; Replace Twitter links by Nitter ;; Replace Twitter links by Nitter
:nitter-urls? false}} :nitter-urls? false}
:transform [{:source {:type :twitter-source
;; optional, defaults to false
:include-replies? false
;; optional, defaults to false
:include-rts? false
;; accounts you wish to mirror
:accounts ["arstechnica" "WIRED"]}
:target {}}]
}
``` ```
* the bot looks for `config.edn` at its relative path by default, an alternative location can be specified either using the `MASTODON_BOT_CONFIG` environment variable or passing the path to config as an argument * the bot looks for `config.edn` at its relative path by default, an alternative location can be specified either using the `MASTODON_BOT_CONFIG` environment variable or passing the path to config as an argument

@ -68,12 +68,13 @@
(let [last-post-time (-> timeline first :created_at (js/Date.))] (let [last-post-time (-> timeline first :created_at (js/Date.))]
;;post from Twitter ;;post from Twitter
(when-let [twitter-auth (twitter-auth config)] (when-let [twitter-auth (twitter-auth config)]
(let [{:keys [accounts]} twitter-auth] (let [{:keys [transform]} config]
(transform/tweets-to-mastodon (doseq [transformation transform]
mastodon-auth (transform/tweets-to-mastodon
twitter-auth mastodon-auth
accounts twitter-auth
last-post-time))) transformation
last-post-time))))
;;post from Tumblr ;;post from Tumblr
(when-let [{:keys [access-keys accounts limit]} (:tumblr config)] (when-let [{:keys [access-keys accounts limit]} (:tumblr config)]
(doseq [account accounts] (doseq [account accounts]

@ -73,12 +73,17 @@
(masto/post-items mastodon-config last-post-time))))) (masto/post-items mastodon-config last-post-time)))))
(defn-spec tweets-to-mastodon any? (defn-spec tweets-to-mastodon any?
[mastodon-config masto/mastodon-auth? [mastodon-auth masto/mastodon-auth?
twitter-config twitter/twitter-auth? twitter-auth twitter/twitter-auth?
accounts (s/* string?) transformation ::transformation
last-post-time any?] last-post-time any?]
(doseq [account accounts] (let [{:keys [source target]} transformation
(twitter/user-timeline {:keys [accounts include-rts? include-replies?]} source]
twitter-config (doseq [account accounts]
account (println account)
(post-tweets mastodon-config last-post-time)))) (twitter/user-timeline
twitter-auth
include-rts?
include-replies?
account
(post-tweets mastodon-auth last-post-time)))))

@ -23,8 +23,8 @@
(def twitter-source? (s/keys :req-un [::include-rts? ::include-replies?])) (def twitter-source? (s/keys :req-un [::include-rts? ::include-replies?]))
(defn-spec twitter-client any? (defn-spec twitter-client any?
[twitter-config twitter-auth?] [twitter-auth twitter-auth?]
(let [{:keys [access-keys]} twitter-config] (let [{:keys [access-keys]} twitter-auth]
(try (try
(twitter. (clj->js access-keys)) (twitter. (clj->js access-keys))
(catch js/Error e (catch js/Error e
@ -52,15 +52,16 @@
:media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)}) :media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)})
(defn-spec user-timeline any? (defn-spec user-timeline any?
[twitter-config twitter-auth? [twitter-auth twitter-auth?
include-rts? ::include-rts?
include-replies? ::include-replies?
account ::account account ::account
callback fn?] callback fn?]
(let [{:keys [include-rts? include-replies?]} twitter-config] (.get (twitter-client twitter-auth)
(.get (twitter-client twitter-config) "statuses/user_timeline"
"statuses/user_timeline" #js {:screen_name account
#js {:screen_name account :tweet_mode "extended"
:tweet_mode "extended" :include_rts (boolean include-rts?)
:include_rts (boolean include-rts?) :exclude_replies (not (boolean include-replies?))}
:exclude_replies (not (boolean include-replies?))} callback))
callback)))