-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrss_gen.py
56 lines (48 loc) · 1.45 KB
/
rss_gen.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
51
52
53
54
55
56
import yaml
import os
from datetime import datetime
import PyRSS2Gen
# Function to read YAML files
def read_yaml(file_path):
with open(file_path, 'r') as file:
return yaml.safe_load(file)
# Function to convert date string to datetime object
def parse_date(date_str):
return datetime.strptime(date_str, '%Y-%m-%d')
# Function to generate RSS feed
def generate_rss(content):
rss_items = []
for entry in content:
item = PyRSS2Gen.RSSItem(
title=entry['name'],
link=f"https://www.example.com{entry['link']}",
description=entry['description'],
guid=PyRSS2Gen.Guid(f"https://www.example.com{entry['link']}"),
pubDate=parse_date(entry['date'])
)
rss_items.append(item)
rss = PyRSS2Gen.RSS2(
title="Your Website Title",
link="https://www.example.com",
description="Description of your website",
lastBuildDate=datetime.now(),
items=rss_items
)
return rss
# Paths to the YAML files
yaml_files = [
'web/data/blogs.yml',
'web/data/projects.yml',
'web/datarobots.yml',
'web/datavideos.yml',
'web/datacourses.yml',
'web/datareviews.yml'
]
# Read content from YAML files
content = []
for file_path in yaml_files:
content.extend(read_yaml(file_path))
# Generate and save RSS feed
rss = generate_rss(content)
rss.write_xml(open("path/to/save/rss.xml", "w"))
print("RSS feed generated and saved successfully.")