Implements check if item is already present

This commit is contained in:
Harm Aarts 2013-12-02 14:25:45 +01:00
parent b311fe3f8d
commit d79101645d
1 changed files with 20 additions and 0 deletions

20
atom.go
View File

@ -71,6 +71,10 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
list = node.SelectNodes(ns, "entry") list = node.SelectNodes(ns, "entry")
for _, item := range list { for _, item := range list {
if isItemPresent(ch, item.S(ns, "id"), item.S(ns, "title")) {
continue
}
i = new(Item) i = new(Item)
i.Title = item.S(ns, "title") i.Title = item.S(ns, "title")
i.Id = item.S(ns, "id") i.Id = item.S(ns, "id")
@ -123,3 +127,19 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
} }
return return
} }
func isItemPresent(ch *Channel, id, title 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
}
}
}
return false
}