diff options
author | Dimitri Sokolyuk <demon@dim13.org> | 2019-07-06 17:17:46 +0200 |
---|---|---|
committer | Dimitri Sokolyuk <demon@dim13.org> | 2019-07-06 17:17:46 +0200 |
commit | 1d2ca509c77cbb2af0475b1319cd840f8ce9a1d0 (patch) | |
tree | 05a838baaf4f96fbcce03d06090a2403ee56c878 /rss.go | |
parent | 87e820722cf02054225b47a58f97d0824118292f (diff) |
Split in packages
Diffstat (limited to 'rss.go')
-rw-r--r-- | rss.go | 56 |
1 files changed, 0 insertions, 56 deletions
@@ -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) - } -} |