Fixed bugs in channel/item identification
This commit is contained in:
parent
f5f5baa34e
commit
31d02da4ae
26
src/atom.go
26
src/atom.go
|
@ -7,20 +7,38 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
|
|||
ns := "http://www.w3.org/2005/Atom"
|
||||
channels := doc.SelectNodes(ns, "feed")
|
||||
|
||||
getChan := func(id string) *Channel {
|
||||
getChan := func(id, title string) *Channel {
|
||||
for _, c := range this.Channels {
|
||||
switch {
|
||||
case len(id) > 0:
|
||||
if c.Id == id {
|
||||
return c
|
||||
}
|
||||
case len(title) > 0:
|
||||
if c.Title == title {
|
||||
return c
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
haveItem := func(ch *Channel, id string) bool {
|
||||
haveItem := func(ch *Channel, id, title, desc string) bool {
|
||||
for _, item := range ch.Items {
|
||||
switch {
|
||||
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
|
||||
}
|
||||
|
@ -31,7 +49,7 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
|
|||
var list []*xmlx.Node
|
||||
|
||||
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)
|
||||
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")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
19
src/rss.go
19
src/rss.go
|
@ -13,27 +13,34 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
|
|||
days["Saturday"] = 6
|
||||
days["Sunday"] = 7
|
||||
|
||||
getChan := func(pubdate string) *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
|
||||
}
|
||||
|
||||
haveItem := func(ch *Channel, id, title, desc string) bool {
|
||||
haveItem := func(ch *Channel, pubdate, title, desc string) bool {
|
||||
for _, item := range ch.Items {
|
||||
switch {
|
||||
case len(id) > 0:
|
||||
if item.Id == id {
|
||||
case len(pubdate) > 0:
|
||||
if item.PubDate == pubdate {
|
||||
return true
|
||||
}
|
||||
case len(title) > 0:
|
||||
if item.Title == title {
|
||||
return true
|
||||
}
|
||||
default:
|
||||
case len(desc) > 0:
|
||||
if item.Description == desc {
|
||||
return true
|
||||
}
|
||||
|
@ -49,7 +56,7 @@ func (this *Feed) readRss2(doc *xmlx.Document) (err os.Error) {
|
|||
|
||||
channels := doc.SelectNodes("", "channel")
|
||||
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)
|
||||
this.Channels = append(this.Channels, ch)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue