2024-09-13 03:03:39 +00:00
|
|
|
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)
|
|
|
|
|
2024-09-21 19:11:41 +00:00
|
|
|
links := []Link{}
|
|
|
|
|
|
|
|
for _, feedItem := range d.Channel.Items {
|
|
|
|
links = append(links, Link{Url: feedItem.Link, Title: feedItem.Title, PublishedDate: feedItem.GetPublishedDate()})
|
|
|
|
}
|
|
|
|
b, _ = json.Marshal(links)
|
2024-09-13 03:03:39 +00:00
|
|
|
cacheKey := fmt.Sprintf("feeds:%s", url)
|
|
|
|
SharedCache.Set(cacheKey, string(b))
|
|
|
|
}
|
|
|
|
|
|
|
|
func refreshFeeds() {
|
|
|
|
for _, url := range SharedCache.List("feedurl") {
|
|
|
|
fetchFeed(url)
|
|
|
|
}
|
|
|
|
}
|