examples/ytfeed.aggregate: better documentation
This commit is contained in:
@@ -4,13 +4,14 @@ import re, sys, xml.etree.ElementTree as ET
|
||||
ET.register_namespace("", "http://www.w3.org/2005/Atom")
|
||||
ET.register_namespace("media", "http://search.yahoo.com/mrss/")
|
||||
ET.register_namespace("yt", "http://www.youtube.com/xml/schemas/2015")
|
||||
def sortby(entry):
|
||||
return entry.findall("{http://www.w3.org/2005/Atom}published")[0].text
|
||||
macrofeed = ET.Element('feed')
|
||||
macrofeed.extend(
|
||||
sorted([
|
||||
entry
|
||||
# Split the input by file.
|
||||
# Split the input by file. This relies on a typical <XML /> tag
|
||||
# starting a file. Theoretically this assumption could be wrong,
|
||||
# but in that case the XML parser would break before
|
||||
# ytfeed.aggregate could spit malformed output.
|
||||
for feed in re.split(r'<\?xml.*?\?>', sys.stdin.read())[1:]
|
||||
# Get the entries out of each file.
|
||||
for entry
|
||||
@@ -18,9 +19,8 @@ macrofeed.extend(
|
||||
.findall("{http://www.w3.org/2005/Atom}entry")
|
||||
],
|
||||
# Gets the publication date and sorts the entries from old to new.
|
||||
key = lambda entry
|
||||
key = lambda entry # (this is a text sort but it still works)
|
||||
: entry.findall("{http://www.w3.org/2005/Atom}published")[0].text,
|
||||
reverse = False # toggle this to switch the order
|
||||
)
|
||||
)
|
||||
print(ET.tostring(macrofeed, encoding="unicode"))
|
||||
|
||||
Reference in New Issue
Block a user