Skip to content

Commit adae3b5

Browse files
author
dalj8690
committed
Updated the script for generating RSS feeds
1 parent 287eeca commit adae3b5

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

generate_rss.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,18 @@ def is_file_updated(file_path, existing_pub_date):
7979
# Add the item to the channel
8080
channel.append(item)
8181

82+
# Sort items in descending order by pubDate (newest first)
83+
items = channel.findall("item")
84+
sorted_items = sorted(items, key=lambda x: datetime.strptime(x.find("pubDate").text, "%a, %d %b %Y %H:%M:%S GMT"), reverse=True)
85+
86+
# Clear existing items and add the sorted items
87+
channel.clear()
88+
for item in sorted_items:
89+
channel.append(item)
90+
8291
# Save the updated RSS feed
8392
if changes_made:
8493
tree.write(rss_file, encoding="utf-8", xml_declaration=True)
8594
print("RSS feed updated.")
8695
else:
87-
print("No changes made to the RSS feed.")
96+
print("No changes made to the RSS feed.")

0 commit comments

Comments
 (0)