-
Notifications
You must be signed in to change notification settings - Fork 2
/
rss_builder.py
50 lines (39 loc) · 1.07 KB
/
rss_builder.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
41
42
43
44
45
46
47
48
49
50
# Kevin McAleer
# April 2023
# RSS Builder
import datetime
from feedgen.feed import FeedGenerator
import yaml
"""
This module builds the RSS feed for the site, including:
blog articles
videos
courses
Reviews
Gear List
Projects
Robots
"""
YOUTUBE_YAML = 'web/_data/youtube.yml'
def generate_from_youtube():
""" Generate the RSS feed from the youtube yaml file """
# read the youtube yaml file
with open(YOUTUBE_YAML, 'r') as file:
data = yaml.safe_load(file)
# create the RSS feed
rss = FeedGenerator(
title='Kevin McAleer - YouTube',
link='https://www.youtube.com/channel/UC4WgR8Kv7VxMx0e5cVWYg8Q',
description='YouTube videos by Kevin McAleer',
lastBuildDate=datetime.datetime.now()
)
# add the items
for item in data:
rss.add_item(
title=item['title'],
link=f"https://www.youtube.com/watch={item['video_id']}",
pubDate=item['published']
)
# write the RSS feed
with open('web/feeds/youtube.xml', 'w') as file:
file.write(rss.to_xml())