Makes rss replace channels and items, thus making it stateless

This commit is contained in:
Harm Aarts 2013-12-05 14:05:24 +01:00
parent 4fa6c97010
commit 6ef84d35e2
1 changed files with 4 additions and 26 deletions

28
rss.go
View File

@ -17,23 +17,7 @@ var days = map[string]int{
} }
func (this *Feed) readRss2(doc *xmlx.Document) (err error) { func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
var foundChannels []*Channel
getChan := func(pubdate, title string) *Channel {
for _, c := range this.Channels {
switch {
case len(pubdate) > 0:
if c.PubDate == pubdate {
return c
}
case len(title) > 0:
if c.Title == title {
return c
}
}
}
return nil
}
var ch *Channel var ch *Channel
var i *Item var i *Item
var n *xmlx.Node var n *xmlx.Node
@ -51,10 +35,8 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
channels := root.SelectNodes(ns, "channel") channels := root.SelectNodes(ns, "channel")
for _, node := range channels { for _, node := range channels {
if ch = getChan(node.S(ns, "pubDate"), node.S(ns, "title")); ch == nil {
ch = new(Channel) ch = new(Channel)
this.Channels = append(this.Channels, ch) foundChannels = append(foundChannels, ch)
}
ch.Title = node.S(ns, "title") ch.Title = node.S(ns, "title")
list = node.SelectNodes(ns, "link") list = node.SelectNodes(ns, "link")
@ -127,7 +109,6 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
ch.TextInput.Link = n.S(ns, "link") ch.TextInput.Link = n.S(ns, "link")
} }
itemcount := len(ch.Items)
list = node.SelectNodes(ns, "item") list = node.SelectNodes(ns, "item")
if len(list) == 0 { if len(list) == 0 {
list = doc.SelectNodes(ns, "item") list = doc.SelectNodes(ns, "item")
@ -195,10 +176,7 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
ch.Items = append(ch.Items, i) ch.Items = append(ch.Items, i)
} }
if itemcount != len(ch.Items) && this.itemhandler != nil {
this.itemhandler(this, ch, ch.Items[itemcount:])
}
} }
this.Channels = foundChannels
return return
} }