From 820cd2be82bde3e35c980147e87689b4adceacc2 Mon Sep 17 00:00:00 2001 From: "dmitri.sotnikov@gmail.com" Date: Thu, 27 Feb 2020 20:23:48 -0500 Subject: [PATCH] added shadow-cljs compilation to generate a js artifact --- mastodon_bot/core.cljs | 28 ++++++++++++++++++++++++++-- mastodon_bot/main.cljs | 28 +++------------------------- package.json | 3 +++ shadow-cljs.edn | 5 +++++ 4 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 shadow-cljs.edn diff --git a/mastodon_bot/core.cljs b/mastodon_bot/core.cljs index 8b9352e..0d5b3f0 100644 --- a/mastodon_bot/core.cljs +++ b/mastodon_bot/core.cljs @@ -198,5 +198,29 @@ (exit-with-error (str "failed to connect to Tumblr account " account ": " (.-message e)))))) -(defn rss-parser [] - (rss.)) +(defn main [] + (get-mastodon-timeline + (fn [timeline] + (let [last-post-time (-> timeline first :created_at (js/Date.))] + ;;post from Twitter + (when-let [twitter-config (:twitter config)] + (let [{:keys [access-keys accounts include-replies? include-rts?]} twitter-config + client (twitter-client access-keys)] + (doseq [account accounts] + (.get client + "statuses/user_timeline" + #js {:screen_name account + :tweet_mode "extended" + :include_rts (boolean include-rts?) + :exclude_replies (not (boolean include-replies?))} + (post-tweets last-post-time))))) + ;;post from Tumblr + (when-let [{:keys [access-keys accounts limit]} (:tumblr config)] + (doseq [account accounts] + (let [client (tumblr-client access-keys account)] + (.posts client #js {:limit (or limit 5)} (post-tumblrs last-post-time))))) + ;;post from RSS + (when-let [feeds (some-> config :rss)] + (let [parser (rss.)] + (doseq [feed feeds] + (parse-feed last-post-time parser feed)))))))) \ No newline at end of file diff --git a/mastodon_bot/main.cljs b/mastodon_bot/main.cljs index 4b0b6d2..976c8e2 100644 --- a/mastodon_bot/main.cljs +++ b/mastodon_bot/main.cljs @@ -4,28 +4,6 @@ (:require [mastodon-bot.core :as core])) -(core/get-mastodon-timeline - (fn [timeline] - (let [last-post-time (-> timeline first :created_at (js/Date.))] - ;;post from Twitter - (when-let [twitter-config (:twitter core/config)] - (let [{:keys [access-keys accounts include-replies? include-rts?]} twitter-config - client (core/twitter-client access-keys)] - (doseq [account accounts] - (.get client - "statuses/user_timeline" - #js {:screen_name account - :tweet_mode "extended" - :include_rts (boolean include-rts?) - :exclude_replies (not (boolean include-replies?))} - (core/post-tweets last-post-time))))) - ;;post from Tumblr - (when-let [{:keys [access-keys accounts limit tumblr-oauth]} (:tumblr core/config)] - (doseq [account accounts] - (let [client (core/tumblr-client access-keys account)] - (.posts client #js {:limit (or limit 5)} (core/post-tumblrs last-post-time))))) - ;;post from RSS - (when-let [feeds (some-> core/config :rss)] - (let [parser (core/rss-parser)] - (doseq [feed feeds] - (core/parse-feed last-post-time parser feed))))))) +(core/main) + + diff --git a/package.json b/package.json index 50fa46a..4969228 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,9 @@ "deasync": "0.1.15", "request": "2.88.0" }, + "devDependencies": { + "shadow-cljs": "^2.8.37" + }, "scripts": { "start": "./mastodon_bot/main.cljs", "test": "MASTODON_BOT_CONFIG=test.edn ./mastodon_bot/core_test.cljs" diff --git a/shadow-cljs.edn b/shadow-cljs.edn new file mode 100644 index 0000000..793e3b5 --- /dev/null +++ b/shadow-cljs.edn @@ -0,0 +1,5 @@ +{:source-paths ["mastodon_bot"] + :dependencies [] + :builds {:app {:target :node-script + :output-to "target/mastodon-bot.js" + :main mastodon-bot.core/main}}}