added RSS support

This commit is contained in:
dmitri.sotnikov@gmail.com 2018-03-20 08:57:25 -04:00
parent 56421bc284
commit 1f411891a8
3 changed files with 22 additions and 2 deletions

View file

@ -1,6 +1,6 @@
### description
the bot will read the timeline from the specified Twitter/Tumblr accounts, and post it to Mastodon
the bot will post the timeline from the specified Twitter/Tumblr accounts and RSS feeds to Mastodon
### installation
@ -30,6 +30,9 @@ the bot will read the timeline from the specified Twitter/Tumblr accounts, and p
:token "XXXX"
:token_secret "XXXX"}
:accounts ["cyberpunky.tumblr.com" "scipunk.tumblr.com"]}
;; add RSS config to follow feeds
:rss {"Hacker News" "https://hnrss.org/newest"
"r/Clojure" "https://www.reddit.com/r/clojure/.rss"}
:mastodon {:access_token "XXXX"
:api_url "https://botsin.space/api/v1/"}}
```

View file

@ -9,6 +9,7 @@
["http" :as http]
["https" :as https]
["mastodon-api" :as mastodon]
["rss-parser" :as rss]
["tumblr" :as tumblr]
["twitter" :as twitter]))
@ -97,15 +98,30 @@
(map parse-tweet)
(post-items last-post-time))))
(defn parse-feed [last-post-time parser [title url]]
(-> (.parseURL parser url)
(.then #(post-items
last-post-time
(for [{:keys [title isoDate content link]} (-> % js->edn :items)]
{:created-at (js/Date. isoDate)
:text (str title "\n\n" link)})))))
(get-mastodon-timeline
(fn [timeline]
(let [last-post-time (-> timeline first :created_at (js/Date.))]
;;post from Twitter
(when-let [twitter-client (some-> config :twitter :access-keys clj->js twitter.)]
(doseq [account (-> config :twitter :accounts)]
(.get twitter-client
"statuses/user_timeline"
#js {:screen_name account :include_rts false}
(post-tweets last-post-time))))
;;post from Tumblr
(when-let [tumblr-oauth (some-> config :tumblr :access-keys clj->js)]
(when-let [tumblr-client (some-> config :tumblr :accounts first (tumblr/Blog. tumblr-oauth))]
(.posts tumblr-client #js {:limit 5} (post-tumblrs last-post-time)))))))
(.posts tumblr-client #js {: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)))))))

View file

@ -6,6 +6,7 @@
"dependencies": {
"lumo-cljs": "^1.8.0",
"mastodon-api": "1.3.0",
"rss-parser": "3.1.2",
"tumblr": "0.4.1",
"twitter": "1.7.1"
},