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)
|
(mastodon-config config)
|
||||||
last-post-time))))
|
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]]
|
(defn parse-feed [last-post-time parser [title url]]
|
||||||
(-> (.parseURL parser url)
|
(-> (.parseURL parser url)
|
||||||
(.then #(masto/post-items
|
(.then #(masto/post-items
|
||||||
|
@ -75,11 +63,11 @@
|
||||||
;;post from Twitter
|
;;post from Twitter
|
||||||
(when-let [twitter-config (:twitter config)]
|
(when-let [twitter-config (:twitter config)]
|
||||||
(let [{:keys [accounts]} twitter-config]
|
(let [{:keys [accounts]} twitter-config]
|
||||||
(doseq [account accounts]
|
(transform/tweets-to-mastodon
|
||||||
(twitter/user-timeline
|
(mastodon-config config)
|
||||||
twitter-config
|
twitter-config
|
||||||
account
|
accounts
|
||||||
(post-tweets last-post-time)))))
|
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]
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
[clojure.spec.test.alpha :as st]
|
[clojure.spec.test.alpha :as st]
|
||||||
[orchestra.core :refer-macros [defn-spec]]
|
[orchestra.core :refer-macros [defn-spec]]
|
||||||
[clojure.string :as string]
|
[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 ::created-at any?)
|
||||||
(s/def ::text string?)
|
(s/def ::text string?)
|
||||||
|
@ -36,13 +39,38 @@
|
||||||
(defn-spec to-mastodon mastodon-output?
|
(defn-spec to-mastodon mastodon-output?
|
||||||
[mastodon-config masto/mastodon-config?
|
[mastodon-config masto/mastodon-config?
|
||||||
input input?]
|
input input?]
|
||||||
(let [{:keys [created-at text media-links screen_name untrimmed-text]} input]
|
(let [{:keys [created-at text media-links screen_name untrimmed-text]} input
|
||||||
{:created-at created-at
|
untrimmed (if (some? untrimmed-text)
|
||||||
:text (str (trim-text
|
|
||||||
text
|
|
||||||
(masto/max-post-length mastodon-config))
|
|
||||||
(if (some? untrimmed-text)
|
|
||||||
(str " " untrimmed-text) "")
|
(str " " untrimmed-text) "")
|
||||||
(if (masto/append-screen-name? mastodon-config)
|
sname (if (masto/append-screen-name? mastodon-config)
|
||||||
(str "\n - " screen_name) ""))
|
(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}))
|
: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