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