morning-coffee/feed_fetch.go

35 lines
537 B
Go
Raw Normal View History

package main
import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
)
func fetchFeed(url string) {
slog.Info((fmt.Sprintf("Fetching %s\n", url)))
re, err := http.Get(url)
if err != nil {
fmt.Printf("%+v", err)
return
}
defer re.Body.Close()
b, _ := io.ReadAll(re.Body)
d := ParseFeed(b)
b, _ = json.Marshal(d.Channel.ItemsToLinks())
cacheKey := fmt.Sprintf("feeds:%s", url)
SharedCache.Set(cacheKey, string(b))
}
func refreshFeeds() {
for _, url := range SharedCache.List("feedurl") {
fetchFeed(url)
}
}