-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileinput_example.py
More file actions
32 lines (29 loc) · 1.1 KB
/
fileinput_example.py
File metadata and controls
32 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import fileinput
import sys
import time
from xml.dom import minidom
from xml.etree.ElementTree import Element, SubElement, tostring
if __name__ == "__main__":
rss = Element(
"rss", {"xmlns:dc": "http://purl.org/dc/elements/1.1", "version": "2.0.0"}
)
channel = SubElement(rss, "channel")
title = SubElement(channel, "title")
title.text = "Sample podcast feed"
desc = SubElement(channel, "description")
desc.text = "Generated for PyMOTW"
pubdate = SubElement(channel, "pubDate")
pubdate.text = time.asctime()
gen = SubElement(channel, "generator")
gen.text = "https://pymotw.com/"
for line in fileinput.input(sys.argv[1:]):
mp3filename = line.strip()
if not mp3filename or mp3filename.startswith("#"):
continue
item = SubElement(rss, "item")
title = SubElement(item, "title")
title.text = mp3filename
encl = SubElement(item, "enclosure", {"type": "audio/mpeg", "url": mp3filename})
rough_string = tostring(rss)
reparsed = minidom.parseString(rough_string)
print(reparsed.toprettyxml(indent=" "))