-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.py
40 lines (29 loc) · 1.83 KB
/
feed.py
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
33
34
35
36
37
38
39
40
import yaml
import xml.etree.ElementTree as xml_tree
with open('feed.yaml','r') as file:
yaml_data = yaml.safe_load(file)
rss_element = xml_tree.Element('rss',{
"version":"2.0" ,
"xmlns:itunes":"http://www.itunes.com/dtds/podcast-1.0.dtd",
"xmlns:content":"http://purl.org/rss/1.0/modules/content/"})
channel_element = xml_tree.SubElement(rss_element,'channel')
link_prefix = yaml_data['link']
xml_tree.SubElement(channel_element,'title').text = yaml_data ['title']
xml_tree.SubElement(channel_element,'format').text = yaml_data ['format']
xml_tree.SubElement(channel_element,'subtitle').text = yaml_data ['subtitle']
xml_tree.SubElement(channel_element,'itunes:author').text = yaml_data ['author']
xml_tree.SubElement(channel_element,'description').text = yaml_data ['description']
xml_tree.SubElement(channel_element,'itunes:image',{'href':link_prefix + yaml_data ['image']})
xml_tree.SubElement(channel_element,'language').text = yaml_data ['category']
xml_tree.SubElement(channel_element,'link').text = link_prefix
xml_tree.SubElement(channel_element,'itunes:category',{'text':yaml_data ['category']})
for item in yaml_data ['item']:
item_element = xml_tree.SubElement(channel_element,'item')
xml_tree.SubElement(item_element,'title').text=item['title']
xml_tree.SubElement(item_element,'itunes:author').text=yaml_data['author']
xml_tree.SubElement(item_element,'description').text=item['description']
xml_tree.SubElement(item_element,'itunes:duration').text=item['duration']
xml_tree.SubElement(item_element,'pubDate').text=item['published']
enclosure = xml_tree.SubElement(item_element,'enclosure',{'url':link_prefix + item['file'],'type':'audio/mpeg','length':item['length']})
output_tree = xml_tree.ElementTree(rss_element)
output_tree.write('podcast.xml',encoding ='UTF-8',xml_declaration =True)