This repository has been archived on 2023-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon-bot/src/main/mastodon_bot/rss_api.cljs

30 lines
729 B
Text
Raw Normal View History

2020-05-31 17:59:20 +00:00
(ns mastodon-bot.rss-api
(:require
[clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]
[orchestra.core :refer-macros [defn-spec]]
["rss-parser" :as rss]
[mastodon-bot.infra :as infra]
))
(s/def ::feed (s/cat :name string? :url string?))
(s/def ::feeds (s/* ::feed))
(def rss-source? (s/keys :req-un [::feeds]))
(defn-spec rss-client any?
[]
(rss.))
2020-05-31 18:08:55 +00:00
(defn parse-feed [item]
(let [{:keys [title isoDate pubDate content link]} item]
2020-05-31 17:59:20 +00:00
{:created-at (js/Date. (or isoDate pubDate))
:text (str title
"\n\n"
2020-05-31 18:01:28 +00:00
link)}))
2020-05-31 17:59:20 +00:00
(defn-spec get-feed map?
[url string?
callback fn?]
(print url)
(-> (.parseURL (rss-client) url)
(.then callback)))