#!/usr/bin/python3
# coding=utf-8

import time
from xml.dom.minidom import parse
from xml.dom.minidom import parseString
from xml.dom.minidom import getDOMImplementation


class AtomEntry:

    def __init__(self, node):
        self.id = node.getElementsByTagName("id")[0].firstChild.nodeValue
        if node.getElementsByTagName("title")[0].firstChild is not None:
            self.title = node.getElementsByTagName("title")[0].firstChild.nodeValue
        else:
            self.title = ""
        try:
            self.updated = time.strptime(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:19], "%Y-%m-%dT%H:%M:%S")
        except:
            try:
                self.updated = time.strptime(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:10], "%Y-%m-%d")
            except:
                print(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:10])
                self.updated = time.localtime()
        if len(node.getElementsByTagName("summary")) > 0 and node.getElementsByTagName("summary")[0].firstChild is not None:
            self.summary = node.getElementsByTagName("summary")[0].firstChild.nodeValue
        else:
            self.summary = None
        if len(node.getElementsByTagName("link")) > 0:
            self.link = node.getElementsByTagName("link")[0].getAttribute("href")
        else:
            self.link = None
        if len(node.getElementsByTagName("category")) >= 1:
            self.category = node.getElementsByTagName("category")[0].getAttribute("term")
        else:
            self.category = None
        if len(node.getElementsByTagName("link")) > 1:
            self.link2 = node.getElementsByTagName("link")[1].getAttribute("href")
        else:
            self.link2 = None


class Atom:

    def __init__(self, string):
        self.raw = string
        self.feed = parseString(string).documentElement
        self.id = self.feed.getElementsByTagName("id")[0].firstChild.nodeValue
        self.title = self.feed.getElementsByTagName("title")[0].firstChild.nodeValue

        self.updated = None
        self.entries = dict()
        for item in self.feed.getElementsByTagName("entry"):
            entry = AtomEntry(item)
            self.entries[entry.id] = entry
            if self.updated is None or self.updated < entry.updated:
                self.updated = entry.updated

    def __str__(self):
        return self.raw

    def diff(self, other):
        differ = list()
        for k in other.entries.keys():
            if self.updated is None and k not in self.entries:
                self.updated = other.entries[k].updated
            if k not in self.entries and other.entries[k].updated >= self.updated:
                differ.append(other.entries[k])
        return differ


if __name__ == "__main__":
  content1 = ""
  with open("rss.php.1", "r") as f:
    for line in f:
      content1 += line
  content2 = ""
  with open("rss.php", "r") as f:
    for line in f:
      content2 += line
  a = Atom(content1)
  print(a.updated)
  b = Atom(content2)
  print(b.updated)

  diff = a.diff(b)
  print(diff)

@@ -28,16 +28,32 @@
 =utf-8%0A%0A
+import datetime%0A
 import t
@@ -56,16 +56,16 @@
 rt time%0A
-
 from xml
@@ -958,16 +958,76 @@
 ltime()%0A
+        self.updated = datetime.datetime(*self.updated%5B:6%5D)%0A
         
@@ -1837,16 +1837,123 @@
 = None%0A%0A
+    def __repr__(self):%0A        return %22%3CAtomEntry title='%25s' updated='%25s'%3E%22 %25 (self.title, self.updated)%0A%0A
 %0Aclass A
@@ -2961,16 +2961,161 @@
 differ%0A%0A
+    def get_ordered_entries(self):%0A        entries = self.entries.values()%0A        return sorted(entries, key=lambda e: e.updated, reverse=True)%0A
 %0Aif __na

use Datetime to store internal dates and can get an ordered list of elements