works with ubuntu

This commit is contained in:
bel
2020-01-29 03:44:44 +00:00
commit ccfefd5b77
9 changed files with 285 additions and 0 deletions

37
feed/feed.go Normal file
View File

@@ -0,0 +1,37 @@
package feed
import (
"net/http"
"strings"
"time"
"github.com/mmcdole/gofeed"
)
func Fetch(s string) ([]Item, error) {
resp, err := http.Get(s)
if err != nil {
return nil, err
}
defer resp.Body.Close()
gofeed, err := gofeed.NewParser().Parse(resp.Body)
if err != nil {
return nil, err
}
links := make([]Item, 0)
for _, item := range gofeed.Items {
timestamp := strings.Split(item.Title, " ")[1]
t, err := time.Parse("1/2/06", timestamp)
if err == nil {
links = append(links, Item{
Link: item.Link,
Title: strings.ReplaceAll(item.Title, "/", "-"),
Date: t,
})
}
}
return links, nil
}

9
feed/item.go Normal file
View File

@@ -0,0 +1,9 @@
package feed
import "time"
type Item struct {
Link string
Date time.Time
Title string
}