clean up, updated docs
This commit is contained in:
parent
97f1df59be
commit
72f85c1a51
5 changed files with 14 additions and 9 deletions
|
@ -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/)
|
1. install [Node.js](https://nodejs.org/en/)
|
||||||
2. run `npm install` to install Node modules
|
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:
|
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
|
* 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:
|
* 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
|
## License
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
["request" :as request]
|
["request" :as request]
|
||||||
["fs" :as fs]
|
["fs" :as fs]
|
||||||
["mastodon-api" :as mastodon]
|
["mastodon-api" :as mastodon]
|
||||||
|
["rss-parser" :as rss]
|
||||||
["tumblr" :as tumblr]
|
["tumblr" :as tumblr]
|
||||||
["twitter" :as twitter]))
|
["twitter" :as twitter]))
|
||||||
|
|
||||||
|
@ -16,9 +17,12 @@
|
||||||
(js/process.exit 1))
|
(js/process.exit 1))
|
||||||
|
|
||||||
(defn find-config []
|
(defn find-config []
|
||||||
(or (first *command-line-args*)
|
(let [config (or (first *command-line-args*)
|
||||||
(-> js/process .-env .-MASTODON_BOT_CONFIG)
|
(-> js/process .-env .-MASTODON_BOT_CONFIG)
|
||||||
"config.edn"))
|
"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))
|
(def config (-> (find-config) (fs/readFileSync #js {:encoding "UTF-8"}) edn/read-string))
|
||||||
|
|
||||||
|
@ -193,3 +197,6 @@
|
||||||
(catch js/Error e
|
(catch js/Error e
|
||||||
(exit-with-error
|
(exit-with-error
|
||||||
(str "failed to connect to Tumblr account " account ": " (.-message e))))))
|
(str "failed to connect to Tumblr account " account ": " (.-message e))))))
|
||||||
|
|
||||||
|
(defn rss-parser []
|
||||||
|
(rss.))
|
||||||
|
|
0
mastodon_bot/core_test.cljs
Executable file → Normal file
0
mastodon_bot/core_test.cljs
Executable file → Normal file
5
mastodon_bot/main.cljs
Executable file → Normal file
5
mastodon_bot/main.cljs
Executable file → Normal file
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
(ns mastodon-bot.main
|
(ns mastodon-bot.main
|
||||||
(:require
|
(:require
|
||||||
[mastodon-bot.core :as core]
|
[mastodon-bot.core :as core]))
|
||||||
["rss-parser" :as rss]))
|
|
||||||
|
|
||||||
(core/get-mastodon-timeline
|
(core/get-mastodon-timeline
|
||||||
(fn [timeline]
|
(fn [timeline]
|
||||||
|
@ -27,6 +26,6 @@
|
||||||
(.posts client #js {:limit (or limit 5)} (core/post-tumblrs last-post-time)))))
|
(.posts client #js {:limit (or limit 5)} (core/post-tumblrs last-post-time)))))
|
||||||
;;post from RSS
|
;;post from RSS
|
||||||
(when-let [feeds (some-> core/config :rss)]
|
(when-let [feeds (some-> core/config :rss)]
|
||||||
(let [parser (rss.)]
|
(let [parser (core/rss-parser)]
|
||||||
(doseq [feed feeds]
|
(doseq [feed feeds]
|
||||||
(core/parse-feed last-post-time parser feed)))))))
|
(core/parse-feed last-post-time parser feed)))))))
|
||||||
|
|
0
poll.sh
Executable file → Normal file
0
poll.sh
Executable file → Normal file
Reference in a new issue