diff options
-rw-r--r-- | feed/feed.go | 23 |
1 files changed, 23 insertions, 0 deletions
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 +} + |