Skip to content

Commit

Permalink
Create feed.py
Browse files Browse the repository at this point in the history
  • Loading branch information
celiotamm authored Jul 5, 2024
1 parent 56dd7e4 commit 392f5b4
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import yaml
import xml.etree.ElementTree as xml_tree

with open ('feed.yaml', 'r') as file:

yaml_data = yaml.safe_load(file) #safe_load assures file is uploading correctly

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']}) # this is a different one
xml_tree.SubElement(channel_element, 'language').text = yaml_data['language']
xml_tree.SubElement(channel_element, 'link').text = link_prefix
xml_tree.SubElement(channel_element, 'itunes:category',{'text': yaml_data['category']}) # like the image



# items are episodes for a postcad

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']

})



# create an outfile

output_tree = xml_tree.ElementTree(rss_element)
output_tree.write('podcast.xml', encoding='UTF-8', xml_declaration=True)

0 comments on commit 392f5b4

Please sign in to comment.