diff --git a/tools/exampleparser.py b/tools/exampleparser.py index b7bda8d0df..7de97a75da 100755 --- a/tools/exampleparser.py +++ b/tools/exampleparser.py @@ -4,6 +4,7 @@ import sys import os import re import urllib2 +import time from xml.dom.minidom import Document missing_deps = False @@ -86,6 +87,11 @@ def createFeed(examples): doc = Document() feed = doc.createElementNS("http://www.w3.org/2005/Atom", "feed") for example in examples: + s = os.stat("../examples/" + example["example"]) + example["modified"] = s.st_mtime + + examples.sort(key=lambda x:x["modified"]) + for example in sorted(examples, key=lambda x:x["modified"], reverse=True): entry = doc.createElementNS("http://www.w3.org/2005/Atom", "entry") title = doc.createElementNS("http://www.w3.org/2005/Atom", "title") @@ -100,6 +106,11 @@ def createFeed(examples): summary.appendChild(doc.createTextNode(example["shortdesc"] or example["example"])) entry.appendChild(summary) + updated = doc.createElementNS("http://www.w3.org/2005/Atom", "updated") + updated.appendChild(doc.createTextNode( + time.strftime("%Y-%m-%dT%I:%M:%SZ",time.gmtime(example["modified"])))) + entry.appendChild(updated) + feed.appendChild(entry) doc.appendChild(feed) @@ -182,7 +193,7 @@ if __name__ == "__main__": print "writing feed to ../examples/example-list.xml " atom = open('../examples/example-list.xml','w') doc = createFeed(exampleList) - atom.write(doc.toprettyxml(" ")) + atom.write(doc.toxml()) atom.close()