summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-11-27 18:57:44 -0500
committersiddharth <s@ricketyspace.net>2021-11-27 18:57:44 -0500
commita3703d923b5516da967164c41f49aa9e2f8a57d7 (patch)
tree2c97e8233c4c9cdcbd503b730fbdb384dcbae82e
parent6da48b8b76eec5864510b6cdbeb5398a5ca3ce97 (diff)
feed: add nprUnmarshal
Unmarshler for a NPR Feed.
-rw-r--r--feed/feed.go23
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
+}
+