mv post tweets to transform
This commit is contained in:
parent
93421abd19
commit
27b29af40a
2 changed files with 43 additions and 27 deletions
|
@ -43,18 +43,6 @@
|
|||
(mastodon-config config)
|
||||
last-post-time))))
|
||||
|
||||
(defn post-tweets [last-post-time]
|
||||
(fn [error tweets response]
|
||||
(if error
|
||||
(infra/exit-with-error error)
|
||||
(->> (infra/js->edn tweets)
|
||||
(map twitter/parse-tweet)
|
||||
(map #(transform/to-mastodon
|
||||
(mastodon-config config) %))
|
||||
(masto/post-items
|
||||
(mastodon-config config)
|
||||
last-post-time)))))
|
||||
|
||||
(defn parse-feed [last-post-time parser [title url]]
|
||||
(-> (.parseURL parser url)
|
||||
(.then #(masto/post-items
|
||||
|
@ -75,11 +63,11 @@
|
|||
;;post from Twitter
|
||||
(when-let [twitter-config (:twitter config)]
|
||||
(let [{:keys [accounts]} twitter-config]
|
||||
(doseq [account accounts]
|
||||
(twitter/user-timeline
|
||||
twitter-config
|
||||
account
|
||||
(post-tweets last-post-time)))))
|
||||
(transform/tweets-to-mastodon
|
||||
(mastodon-config config)
|
||||
twitter-config
|
||||
accounts
|
||||
last-post-time)))
|
||||
;;post from Tumblr
|
||||
(when-let [{:keys [access-keys accounts limit]} (:tumblr config)]
|
||||
(doseq [account accounts]
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
[clojure.spec.test.alpha :as st]
|
||||
[orchestra.core :refer-macros [defn-spec]]
|
||||
[clojure.string :as string]
|
||||
[mastodon-bot.mastodon-api :as masto]))
|
||||
[mastodon-bot.infra :as infra]
|
||||
[mastodon-bot.mastodon-api :as masto]
|
||||
[mastodon-bot.twitter-api :as twitter]
|
||||
[mastodon-bot.tumblr-api :as tumblr]))
|
||||
|
||||
(s/def ::created-at any?)
|
||||
(s/def ::text string?)
|
||||
|
@ -36,13 +39,38 @@
|
|||
(defn-spec to-mastodon mastodon-output?
|
||||
[mastodon-config masto/mastodon-config?
|
||||
input input?]
|
||||
(let [{:keys [created-at text media-links screen_name untrimmed-text]} input]
|
||||
{:created-at created-at
|
||||
:text (str (trim-text
|
||||
text
|
||||
(masto/max-post-length mastodon-config))
|
||||
(if (some? untrimmed-text)
|
||||
(let [{:keys [created-at text media-links screen_name untrimmed-text]} input
|
||||
untrimmed (if (some? untrimmed-text)
|
||||
(str " " untrimmed-text) "")
|
||||
(if (masto/append-screen-name? mastodon-config)
|
||||
(str "\n - " screen_name) ""))
|
||||
:media-links media-links}))
|
||||
sname (if (masto/append-screen-name? mastodon-config)
|
||||
(str "\n - " screen_name) "")
|
||||
trim-length (- (masto/max-post-length mastodon-config)
|
||||
(count untrimmed)
|
||||
(count sname))]
|
||||
{:created-at created-at
|
||||
:text (str (trim-text text trim-length)
|
||||
untrimmed
|
||||
sname)
|
||||
:media-links media-links}))
|
||||
|
||||
(defn-spec post-tweets any?
|
||||
[mastodon-config masto/mastodon-config?
|
||||
last-post-time any?]
|
||||
(fn [error tweets response]
|
||||
(if error
|
||||
(infra/exit-with-error error)
|
||||
(->> (infra/js->edn tweets)
|
||||
(map twitter/parse-tweet)
|
||||
(map #(to-mastodon mastodon-config %))
|
||||
(masto/post-items mastodon-config last-post-time)))))
|
||||
|
||||
(defn-spec tweets-to-mastodon any?
|
||||
[mastodon-config masto/mastodon-config?
|
||||
twitter-config twitter/twitter-config?
|
||||
accounts (s/* string?)
|
||||
last-post-time any?]
|
||||
(doseq [account accounts]
|
||||
(twitter/user-timeline
|
||||
twitter-config
|
||||
account
|
||||
(post-tweets mastodon-config last-post-time))))
|
||||
|
|
Reference in a new issue