update so its merges feeds and sorts newest to oldest
This commit is contained in:
parent
96cff5792c
commit
87a01d3df0
46
main.go
46
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("<body>")
|
||||
fmt.Println("<ul>")
|
||||
|
||||
items := []gofeed.Item{}
|
||||
|
||||
s := bufio.NewScanner(os.Stdin)
|
||||
for s.Scan() {
|
||||
fp := gofeed.NewParser()
|
||||
|
@ -29,10 +54,21 @@ func main () {
|
|||
log.Println(err)
|
||||
} else {
|
||||
for _, item := range feed.Items {
|
||||
fmt.Printf("<li><a href=\"%s\">%s</a><p>%s</p></li>\n", item.Link, item.Title, item.Description)
|
||||
items = append(items, *item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info := RSSInfo{
|
||||
Items: items,
|
||||
}
|
||||
|
||||
sort.Sort(info)
|
||||
|
||||
for _, item := range info.Items {
|
||||
fmt.Printf("<li><a href=\"%s\">%s</a><p>%s</p></li>\n", item.Link, item.Title, item.Description)
|
||||
}
|
||||
|
||||
fmt.Println("</ul>")
|
||||
fmt.Println("</body>")
|
||||
fmt.Println("</html>")
|
||||
|
|
Loading…
Reference in New Issue