Improve console log
This commit is contained in:
parent
9cb7ba4621
commit
2f46c6520a
6 changed files with 66 additions and 66 deletions
|
@ -2,7 +2,7 @@
|
|||
"name": "mastodon-bot",
|
||||
"description": "Bot to publish twitter, tumblr or rss posts to an mastodon account.",
|
||||
"author": "Dmitri Sotnikov",
|
||||
"version": "1.11.1-SNAPSHOT",
|
||||
"version": "1.12.0-SNAPSHOT",
|
||||
"homepage": "https://github.com/yogthos/mastodon-bot",
|
||||
"repository": "https://www.npmjs.com/package/mastodon-bot",
|
||||
"license": "MIT",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(defproject dda/mastodon-bot "1.11.1-SNAPSHOT"
|
||||
(defproject dda/mastodon-bot "1.12.0-SNAPSHOT"
|
||||
:description "Bot to publish twitter, tumblr or rss posts to an mastodon account."
|
||||
:url "https://github.com/yogthos/mastodon-bot"
|
||||
:author "Dmitri Sotnikov"
|
||||
|
|
|
@ -6,11 +6,15 @@
|
|||
["deasync" :as deasync]
|
||||
["node-fetch" :as fetch]))
|
||||
|
||||
(defn debug [item]
|
||||
(defn log-error [item]
|
||||
(js/console.error item)
|
||||
item)
|
||||
|
||||
(defn log [item]
|
||||
(js/console.log item)
|
||||
item)
|
||||
|
||||
(defn debug-first [item]
|
||||
(defn log-first [item]
|
||||
(js/console.log (first item))
|
||||
item)
|
||||
|
||||
|
@ -47,10 +51,13 @@
|
|||
|
||||
(defn resolve-promise [promise result-on-error]
|
||||
(let [done (atom false)
|
||||
result (atom nil)
|
||||
promise (-> promise
|
||||
result (atom nil)]
|
||||
(-> promise
|
||||
(.then #(do (reset! result %) (reset! done true)))
|
||||
(.catch #(do (reset! result result-on-error) (reset! done true))))]
|
||||
(.catch #(do
|
||||
(log-error %)
|
||||
(reset! result result-on-error)
|
||||
(reset! done true))))
|
||||
(.loopWhile deasync (fn [] (not @done)))
|
||||
@result))
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(:require
|
||||
[orchestra.core :refer-macros [defn-spec]]
|
||||
[mastodon-bot.rss-domain :as rd]
|
||||
[mastodon-bot.infra :as infra]
|
||||
[clojure.spec.alpha :as s]
|
||||
["rss-parser" :as rss]))
|
||||
|
||||
|
@ -20,9 +21,5 @@
|
|||
link)}))
|
||||
|
||||
(defn-spec get-feed map?
|
||||
[url string?
|
||||
callback fn?]
|
||||
(print url)
|
||||
(-> (.parseURL (rss-client) url)
|
||||
(.then callback)
|
||||
(.catch #(js/console.log %))))
|
||||
[url string?]
|
||||
(infra/resolve-promise (.parseURL (rss-client) url) []))
|
||||
|
|
|
@ -43,13 +43,11 @@
|
|||
(update input :text #(reduce-kv string/replace % (:replacements transformation))))
|
||||
|
||||
(defn-spec post-tweets-to-mastodon any?
|
||||
[mastodon-auth md/mastodon-auth?
|
||||
[tweets any?
|
||||
mastodon-auth md/mastodon-auth?
|
||||
transformation ::trd/transformation
|
||||
last-post-time any?]
|
||||
(let [{:keys [source target resolve-urls?]} transformation]
|
||||
(fn [error tweets response]
|
||||
(if error
|
||||
(infra/exit-with-error error)
|
||||
(->> (infra/js->edn tweets)
|
||||
(map twa/parse-tweet)
|
||||
(filter #(> (:created-at %) last-post-time))
|
||||
|
@ -58,23 +56,20 @@
|
|||
(map #(twa/nitter-url source %))
|
||||
(map #(perform-replacements transformation %))
|
||||
(map #(ma/intermediate-to-mastodon target %))
|
||||
(ma/post-items mastodon-auth target))))))
|
||||
(ma/post-items mastodon-auth target))))
|
||||
|
||||
(defn-spec tweets-to-mastodon any?
|
||||
[mastodon-auth md/mastodon-auth?
|
||||
twitter-auth twd/twitter-auth?
|
||||
transformation ::trd/transformation
|
||||
last-post-time any?]
|
||||
(let [{:keys [source target resolve-urls?]} transformation]
|
||||
(doseq [account (:accounts source)]
|
||||
(twa/user-timeline
|
||||
twitter-auth
|
||||
source
|
||||
account
|
||||
(post-tweets-to-mastodon
|
||||
mastodon-auth
|
||||
transformation
|
||||
last-post-time)))))
|
||||
(let [{:keys [source target resolve-urls?]} transformation
|
||||
accounts (:accounts source)]
|
||||
(infra/log (str "processing tweets for " accounts))
|
||||
(doseq [account accounts]
|
||||
(-> (twa/user-timeline twitter-auth source account)
|
||||
(post-tweets-to-mastodon mastodon-auth transformation last-post-time)))
|
||||
(infra/log "done.")))
|
||||
|
||||
(defn-spec post-tumblr-to-mastodon any?
|
||||
[mastodon-auth md/mastodon-auth?
|
||||
|
@ -98,7 +93,9 @@
|
|||
tumblr-auth td/tumblr-auth?
|
||||
transformation ::trd/transformation
|
||||
last-post-time any?]
|
||||
(let [{:keys [accounts limit]} transformation]
|
||||
(let [{:keys [source target]} transformation
|
||||
{:keys [accounts limit]} source]
|
||||
(infra/log (str "processing tumblr for " accounts))
|
||||
(doseq [account accounts]
|
||||
(let [client (ta/tumblr-client tumblr-auth account)]
|
||||
(.posts client
|
||||
|
@ -110,11 +107,11 @@
|
|||
)))))
|
||||
|
||||
(defn-spec post-rss-to-mastodon any?
|
||||
[mastodon-auth md/mastodon-auth?
|
||||
[payload any?
|
||||
mastodon-auth md/mastodon-auth?
|
||||
transformation ::trd/transformation
|
||||
last-post-time any?]
|
||||
(let [{:keys [source target resolve-urls?]} transformation]
|
||||
(fn [payload]
|
||||
(->> (infra/js->edn payload)
|
||||
(:items)
|
||||
(map ra/parse-feed)
|
||||
|
@ -123,18 +120,17 @@
|
|||
(map #(intermediate-resolve-urls resolve-urls? %))
|
||||
(map #(perform-replacements transformation %))
|
||||
(map #(ma/intermediate-to-mastodon target %))
|
||||
(ma/post-items mastodon-auth target)))))
|
||||
(ma/post-items mastodon-auth target))))
|
||||
|
||||
|
||||
(defn-spec rss-to-mastodon any?
|
||||
[mastodon-auth md/mastodon-auth?
|
||||
transformation ::trd/transformation
|
||||
last-post-time any?]
|
||||
(let [{:keys [source target]} transformation]
|
||||
(doseq [[name url] (:feeds source)]
|
||||
(ra/get-feed
|
||||
url
|
||||
(post-rss-to-mastodon
|
||||
mastodon-auth
|
||||
transformation
|
||||
last-post-time)))))
|
||||
(let [{:keys [source target]} transformation
|
||||
{:keys [feeds]} source]
|
||||
(infra/log (str "processing rss for " feeds))
|
||||
(doseq [[name url] feeds]
|
||||
(-> (ra/get-feed url)
|
||||
(post-rss-to-mastodon mastodon-auth transformation last-post-time)))
|
||||
(infra/log "done.")))
|
|
@ -46,14 +46,14 @@
|
|||
(defn-spec user-timeline any?
|
||||
[twitter-auth td/twitter-auth?
|
||||
source td/twitter-source?
|
||||
account ::td/account
|
||||
callback fn?]
|
||||
account ::td/account]
|
||||
(let [{:keys [include-rts? include-replies?]} source]
|
||||
(infra/resolve-promise
|
||||
(.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)))
|
||||
:exclude_replies (not (boolean include-replies?))})
|
||||
[])))
|
||||
|
Reference in a new issue