From 72f85c1a5103fe97ff791b6ad8a35cf836bf1986 Mon Sep 17 00:00:00 2001 From: "dmitri.sotnikov@gmail.com" Date: Thu, 27 Feb 2020 17:12:07 -0500 Subject: [PATCH] clean up, updated docs --- README.md | 5 ++--- mastodon_bot/core.cljs | 13 ++++++++++--- mastodon_bot/core_test.cljs | 0 mastodon_bot/main.cljs | 5 ++--- poll.sh | 0 5 files changed, 14 insertions(+), 9 deletions(-) mode change 100755 => 100644 mastodon_bot/core_test.cljs mode change 100755 => 100644 mastodon_bot/main.cljs mode change 100755 => 100644 poll.sh diff --git a/README.md b/README.md index 0d6cbbe..765b7e4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ the bot will post the timeline from the specified Twitter/Tumblr accounts and RS 1. install [Node.js](https://nodejs.org/en/) 2. run `npm install` to install Node modules -3. run `npm start` to, well, start If you wish to run the script directly, you will need to have [Lumo](https://github.com/anmonteiro/lumo) available on the shell path. Lumo can be installed globally via NPM by running: @@ -87,10 +86,10 @@ with later timestamps to avoid duplicate posts. On the first run the timestamp w * the bot looks for `config.edn` at its relative path by default, an alternative location can be specified either using the `MASTODON_BOT_CONFIG` environment variable or passing the path to config as an argument -* run the bot: `./mastodon-bot.cljs` +* run the bot: `npm start` * to poll at intervals setup a cron job such as: - */30 * * * * mastodon-bot.cljs /path/to/config.edn > /dev/null 2>&1 + */30 * * * * npm start /path/to/config.edn > /dev/null 2>&1 ## License diff --git a/mastodon_bot/core.cljs b/mastodon_bot/core.cljs index d59c691..8b9352e 100644 --- a/mastodon_bot/core.cljs +++ b/mastodon_bot/core.cljs @@ -8,6 +8,7 @@ ["request" :as request] ["fs" :as fs] ["mastodon-api" :as mastodon] + ["rss-parser" :as rss] ["tumblr" :as tumblr] ["twitter" :as twitter])) @@ -16,9 +17,12 @@ (js/process.exit 1)) (defn find-config [] - (or (first *command-line-args*) - (-> js/process .-env .-MASTODON_BOT_CONFIG) - "config.edn")) + (let [config (or (first *command-line-args*) + (-> js/process .-env .-MASTODON_BOT_CONFIG) + "config.edn")] + (if (fs/existsSync config) + config + (exit-with-error (str "failed to read config: " config))))) (def config (-> (find-config) (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string)) @@ -193,3 +197,6 @@ (catch js/Error e (exit-with-error (str "failed to connect to Tumblr account " account ": " (.-message e)))))) + +(defn rss-parser [] + (rss.)) diff --git a/mastodon_bot/core_test.cljs b/mastodon_bot/core_test.cljs old mode 100755 new mode 100644 diff --git a/mastodon_bot/main.cljs b/mastodon_bot/main.cljs old mode 100755 new mode 100644 index 17d0634..4b0b6d2 --- a/mastodon_bot/main.cljs +++ b/mastodon_bot/main.cljs @@ -2,8 +2,7 @@ (ns mastodon-bot.main (:require - [mastodon-bot.core :as core] - ["rss-parser" :as rss])) + [mastodon-bot.core :as core])) (core/get-mastodon-timeline (fn [timeline] @@ -27,6 +26,6 @@ (.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 (rss.)] + (let [parser (core/rss-parser)] (doseq [feed feeds] (core/parse-feed last-post-time parser feed))))))) diff --git a/poll.sh b/poll.sh old mode 100755 new mode 100644