summaryrefslogtreecommitdiff
path: root/rss.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2019-07-06 17:17:46 +0200
committerDimitri Sokolyuk <demon@dim13.org>2019-07-06 17:17:46 +0200
commit1d2ca509c77cbb2af0475b1319cd840f8ce9a1d0 (patch)
tree05a838baaf4f96fbcce03d06090a2403ee56c878 /rss.go
parent87e820722cf02054225b47a58f97d0824118292f (diff)
Split in packages
Diffstat (limited to 'rss.go')
-rw-r--r--rss.go56
1 files changed, 0 insertions, 56 deletions
diff --git a/rss.go b/rss.go
deleted file mode 100644
index d14db94..0000000
--- a/rss.go
+++ /dev/null
@@ -1,56 +0,0 @@
-package main
-
-import (
- "fmt"
- "io"
- "log"
- "time"
-
- "dim13.org/rss"
-)
-
-type feed struct {
- Name string
- URL string
- Every time.Duration
-}
-
-type news struct {
- feed
- rss.Item
-}
-
-func (n news) String() string {
- s := fmt.Sprintf("%v: %v", n.Name, n.Title)
- if n.Author != "" {
- s += fmt.Sprintf(" (%v) ", n.Author)
- } else {
- s += " - "
- }
- s += fmt.Sprintf("%v", n.Link)
- return s
-}
-
-func (f feed) watch(w io.Writer) {
- ticker := time.NewTicker(f.Every)
- defer ticker.Stop()
- for t := range ticker.C {
- r, err := rss.Fetch(f.URL)
- if err != nil {
- log.Println(f.Name, err)
- return
- }
- last := t.Add(-f.Every)
- for _, i := range r.Channel.Items {
- if i.PubDate.After(last) {
- fmt.Fprint(w, news{f, i})
- }
- }
- }
-}
-
-func watch(w io.Writer, feeds []feed) {
- for _, feed := range feeds {
- go feed.watch(w)
- }
-}