Script to create a file containing an RSS feed based on a specific tag in writefreely.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

from bs4 import BeautifulSoup
from datetime import datetime
import requests
from feedgen.feed import FeedGenerator
url = ""
feedtitle = "Cespo Fedora feed"
description = "writefreely Fedora tags"
authorname = "alciregi"
authormail = ""
selflink = ""
destpath = ""
fg = FeedGenerator()
fg.subtitle(description), rel='self' ) {'name': authorname,'email': authormail} ), rel='alternate' )
#fg.subtitle('This is a cool feed!')
page = requests.get(url)
soup = BeautifulSoup(page.content,features="lxml")
for i in soup.find_all('article'):
title = i.find("h2", {"class": "post-title"}).find("a").contents[0]
link = i.find("a", href=True)['href']
date = i.find("time", {"class": "dt-published"})["datetime"].split(".")[0]
tz = i.find("time", {"class": "dt-published"})["datetime"].split(".")[1].split(" ")[1]
time_in_datetime = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
pubdate = time_in_datetime.strftime('%a, %d %b %Y %H:%M:%S')+" "+tz
#Sat, 01 Feb 2020 17:05:25 +0000
content = ""
for p in i.find_all('p'):
fe = fg.add_entry()
atomfeed = fg.atom_str(pretty=True) # Get the ATOM feed as string
rssfeed = fg.rss_str(pretty=True) # Get the RSS feed as string
fg.atom_file(destpath+'/atom.xml', pretty=True) # Write the ATOM feed to a file
fg.rss_file(destpath+'/rss.xml', pretty=True) # Write the RSS feed to a file