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_secret "XXXX"
:access_token_key "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"]}
:access_token_secret "XXXX"}}
;; add Tumblr config to mirror Tumblr accounts
:tumblr {:access-keys
{: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
:keyword-filters [".*clojure.*"]
;; 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

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

@ -73,12 +73,17 @@
(masto/post-items mastodon-config last-post-time)))))
(defn-spec tweets-to-mastodon any?
[mastodon-config masto/mastodon-auth?
twitter-config twitter/twitter-auth?
accounts (s/* string?)
[mastodon-auth masto/mastodon-auth?
twitter-auth twitter/twitter-auth?
transformation ::transformation
last-post-time any?]
(doseq [account accounts]
(twitter/user-timeline
twitter-config
account
(post-tweets mastodon-config last-post-time))))
(let [{:keys [source target]} transformation
{:keys [accounts include-rts? include-replies?]} source]
(doseq [account accounts]
(println account)
(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?]))
(defn-spec twitter-client any?
[twitter-config twitter-auth?]
(let [{:keys [access-keys]} twitter-config]
[twitter-auth twitter-auth?]
(let [{:keys [access-keys]} twitter-auth]
(try
(twitter. (clj->js access-keys))
(catch js/Error e
@ -52,15 +52,16 @@
:media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)})
(defn-spec user-timeline any?
[twitter-config twitter-auth?
[twitter-auth twitter-auth?
include-rts? ::include-rts?
include-replies? ::include-replies?
account ::account
callback fn?]
(let [{:keys [include-rts? include-replies?]} twitter-config]
(.get (twitter-client twitter-config)
"statuses/user_timeline"
#js {:screen_name account
:tweet_mode "extended"
:include_rts (boolean include-rts?)
:exclude_replies (not (boolean include-replies?))}
callback)))
(.get (twitter-client twitter-auth)
"statuses/user_timeline"
#js {:screen_name account
:tweet_mode "extended"
:include_rts (boolean include-rts?)
:exclude_replies (not (boolean include-replies?))}
callback))