Fixed bugs in channel/item identification

This commit is contained in:
jim teeuwen 2010-12-18 19:11:37 +01:00
parent f5f5baa34e
commit 31d02da4ae
2 changed files with 41 additions and 16 deletions

View File

@ -7,19 +7,37 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
ns := "http://www.w3.org/2005/Atom" ns := "http://www.w3.org/2005/Atom"
channels := doc.SelectNodes(ns, "feed") channels := doc.SelectNodes(ns, "feed")
getChan := func(id string) *Channel { getChan := func(id, title string) *Channel {
for _, c := range this.Channels { for _, c := range this.Channels {
if c.Id == id { switch {
return c case len(id) > 0:
if c.Id == id {
return c
}
case len(title) > 0:
if c.Title == title {
return c
}
} }
} }
return nil return nil
} }
haveItem := func(ch *Channel, id string) bool { haveItem := func(ch *Channel, id, title, desc string) bool {
for _, item := range ch.Items { for _, item := range ch.Items {
if item.Id == id { switch {
return true case len(id) > 0:
if item.Id == id {
return true
}
case len(title) > 0:
if item.Title == title {
return true
}
case len(desc) > 0:
if item.Description == desc {
return true
}
} }
} }
return false return false
@ -31,7 +49,7 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
var list []*xmlx.Node var list []*xmlx.Node
for _, node := range channels { for _, node := range channels {
if ch = getChan(node.GetValue("", "pubDate")); ch == nil { if ch = getChan(node.GetValue(ns, "id"), node.GetValue(ns, "title")); ch == nil {
ch = new(Channel) ch = new(Channel)
this.Channels = append(this.Channels, ch) this.Channels = append(this.Channels, ch)
} }
@ -74,7 +92,7 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
list = node.SelectNodes(ns, "entry") list = node.SelectNodes(ns, "entry")
for _, item := range list { for _, item := range list {
if haveItem(ch, item.GetValue("", "id")) { if haveItem(ch, item.GetValue(ns, "id"), item.GetValue(ns, "title"), item.GetValue(ns, "summary")) {
continue continue
} }

View File

@ -13,27 +13,34 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
days["Saturday"] = 6 days["Saturday"] = 6
days["Sunday"] = 7 days["Sunday"] = 7
getChan := func(pubdate string) *Channel { getChan := func(pubdate, title string) *Channel {
for _, c := range this.Channels { for _, c := range this.Channels {
if c.PubDate == pubdate { switch {
return c case len(pubdate) > 0:
if c.PubDate == pubdate {
return c
}
case len(title) > 0:
if c.Title == title {
return c
}
} }
} }
return nil return nil
} }
haveItem := func(ch *Channel, id, title, desc string) bool { haveItem := func(ch *Channel, pubdate, title, desc string) bool {
for _, item := range ch.Items { for _, item := range ch.Items {
switch { switch {
case len(id) > 0: case len(pubdate) > 0:
if item.Id == id { if item.PubDate == pubdate {
return true return true
} }
case len(title) > 0: case len(title) > 0:
if item.Title == title { if item.Title == title {
return true return true
} }
default: case len(desc) > 0:
if item.Description == desc { if item.Description == desc {
return true return true
} }
@ -49,7 +56,7 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
channels := doc.SelectNodes("", "channel") channels := doc.SelectNodes("", "channel")
for _, node := range channels { for _, node := range channels {
if ch = getChan(node.GetValue("", "pubDate")); ch == nil { if ch = getChan(node.GetValue("", "pubDate"), node.GetValue("", "title")); ch == nil {
ch = new(Channel) ch = new(Channel)
this.Channels = append(this.Channels, ch) this.Channels = append(this.Channels, ch)
} }