From d79101645df6026cdbe48b07307fe101413a7729 Mon Sep 17 00:00:00 2001 From: Harm Aarts Date: Mon, 2 Dec 2013 14:25:45 +0100 Subject: [PATCH] Implements check if item is already present --- atom.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/atom.go b/atom.go index ccbe786..08808a6 100644 --- a/atom.go +++ b/atom.go @@ -71,6 +71,10 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) { list = node.SelectNodes(ns, "entry") for _, item := range list { + if isItemPresent(ch, item.S(ns, "id"), item.S(ns, "title")) { + continue + } + i = new(Item) i.Title = item.S(ns, "title") i.Id = item.S(ns, "id") @@ -123,3 +127,19 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) { } 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 +}