From a3703d923b5516da967164c41f49aa9e2f8a57d7 Mon Sep 17 00:00:00 2001 From: siddharth Date: Sat, 27 Nov 2021 18:57:44 -0500 Subject: feed: add nprUnmarshal Unmarshler for a NPR Feed. --- feed/feed.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'feed') diff --git a/feed/feed.go b/feed/feed.go index 109de5e..b20a281 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -4,11 +4,15 @@ package feed import ( + "encoding/xml" "fmt" "io" "net/http" "os" "path" + "time" + + "ricketyspace.net/fern/schema" ) type Feed struct { @@ -82,3 +86,22 @@ func (feed *Feed) get() ([]byte, error) { return bs, nil } + +// Unmarshal a NPR feed. +func nprUnmarshal(bs []byte) (schema.NPRFeed, error) { + nprFeed := new(schema.NPRFeed) + err := xml.Unmarshal(bs, nprFeed) + if err != nil { + return *nprFeed, err + } + + // Parse time for all entries. + for i, entry := range nprFeed.Entries { + nprFeed.Entries[i].PubTime, err = time.Parse(time.RFC1123Z, entry.Pub) + if err != nil { + return *nprFeed, err + } + } + return *nprFeed, nil +} + -- cgit v1.2.3