[networking.atom] use Datetime to store internal dates and can get an ordered list of elements
This commit is contained in:
parent
bbf5acafbb
commit
471feca8fb
1 changed files with 8 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
|
import datetime
|
||||||
import time
|
import time
|
||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parse
|
||||||
from xml.dom.minidom import parseString
|
from xml.dom.minidom import parseString
|
||||||
|
@ -23,6 +24,7 @@ class AtomEntry:
|
||||||
except:
|
except:
|
||||||
print(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:10])
|
print(node.getElementsByTagName("updated")[0].firstChild.nodeValue[:10])
|
||||||
self.updated = time.localtime()
|
self.updated = time.localtime()
|
||||||
|
self.updated = datetime.datetime(*self.updated[:6])
|
||||||
if len(node.getElementsByTagName("summary")) > 0 and node.getElementsByTagName("summary")[0].firstChild is not None:
|
if len(node.getElementsByTagName("summary")) > 0 and node.getElementsByTagName("summary")[0].firstChild is not None:
|
||||||
self.summary = node.getElementsByTagName("summary")[0].firstChild.nodeValue
|
self.summary = node.getElementsByTagName("summary")[0].firstChild.nodeValue
|
||||||
else:
|
else:
|
||||||
|
@ -40,6 +42,9 @@ class AtomEntry:
|
||||||
else:
|
else:
|
||||||
self.link2 = None
|
self.link2 = None
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<AtomEntry title='%s' updated='%s'>" % (self.title, self.updated)
|
||||||
|
|
||||||
|
|
||||||
class Atom:
|
class Atom:
|
||||||
|
|
||||||
|
@ -69,6 +74,9 @@ class Atom:
|
||||||
differ.append(other.entries[k])
|
differ.append(other.entries[k])
|
||||||
return differ
|
return differ
|
||||||
|
|
||||||
|
def get_ordered_entries(self):
|
||||||
|
entries = self.entries.values()
|
||||||
|
return sorted(entries, key=lambda e: e.updated, reverse=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
content1 = ""
|
content1 = ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue