make parsing feeds into function

This commit is contained in:
filifa 2024-06-18 18:57:04 -05:00
parent 9dd67e684c
commit b331955266
1 changed files with 11 additions and 6 deletions

View File

@ -37,12 +37,7 @@ func formatItem(item *gofeed.Item, tmpl *template.Template) (string, error) {
return html.UnescapeString(b.String()), err return html.UnescapeString(b.String()), err
} }
func rssfetch(cmd *cobra.Command, urls []string) { func parseFeeds(urls []string) []*gofeed.Feed {
tmpl, err := template.New("out").Parse(output)
if err != nil {
log.Fatal(err)
}
fp := gofeed.NewParser() fp := gofeed.NewParser()
var feedChs []chan *gofeed.Feed var feedChs []chan *gofeed.Feed
for _, url := range urls { for _, url := range urls {
@ -62,6 +57,16 @@ func rssfetch(cmd *cobra.Command, urls []string) {
feeds = append(feeds, <-feedCh) feeds = append(feeds, <-feedCh)
} }
return feeds
}
func rssfetch(cmd *cobra.Command, urls []string) {
tmpl, err := template.New("out").Parse(output)
if err != nil {
log.Fatal(err)
}
feeds := parseFeeds(urls)
for _, feed := range feeds { for _, feed := range feeds {
for _, item := range feed.Items { for _, item := range feed.Items {
out, err := formatItem(item, tmpl) out, err := formatItem(item, tmpl)