From 87a01d3df0445f3a6804006469793d256e82fc6c Mon Sep 17 00:00:00 2001 From: zongor Date: Mon, 26 Aug 2024 22:49:39 -0400 Subject: [PATCH] update so its merges feeds and sorts newest to oldest --- main.go | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 9f9d8a4..10accd9 100644 --- a/main.go +++ b/main.go @@ -1,18 +1,41 @@ package main import ( + "bufio" "context" "fmt" "log" "os" - "time" - "bufio" + "sort" "strings" - + "time" + "github.com/mmcdole/gofeed" ) -func main () { +type RSSInfo struct { + Items []gofeed.Item +} + +// Len returns the length of Items. +func (f RSSInfo) Len() int { + return len(f.Items) +} + +// Less compares PublishedParsed of Items[i], Items[k] +// and returns true if Items[i] is less than Items[k]. +func (f RSSInfo) Less(i, k int) bool { + return f.Items[k].PublishedParsed.Before( + *f.Items[i].PublishedParsed, + ) +} + +// Swap swaps Items[i] and Items[k]. +func (f RSSInfo) Swap(i, k int) { + f.Items[i], f.Items[k] = f.Items[k], f.Items[i] +} + +func main() { ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel() @@ -21,6 +44,8 @@ func main () { fmt.Println("") fmt.Println("") fmt.Println("") fmt.Println("")