parent
2aaeba8bb7
commit
3e7cf17b62
@ -0,0 +1,65 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from datetime import datetime
|
||||
import requests
|
||||
from feedgen.feed import FeedGenerator
|
||||
|
||||
url = "https://cespo.oless.xyz/tag:fedora"
|
||||
feedtitle = "Cespo Fedora feed"
|
||||
description = "writefreely Fedora tags"
|
||||
authorname = "alciregi"
|
||||
authormail = "alciregi@posteo.net"
|
||||
selflink = "https://cespo.oless.xyz/feed/fedora.xml"
|
||||
destpath = ""
|
||||
|
||||
fg = FeedGenerator()
|
||||
fg.id(url)
|
||||
fg.title(feedtitle)
|
||||
fg.subtitle(description)
|
||||
#fg.link(href=selflink, rel='self' )
|
||||
fg.author( {'name': authorname,'email': authormail} )
|
||||
fg.link(href=url, rel='alternate' )
|
||||
|
||||
#fg.logo('http://ex.com/logo.jpg')
|
||||
#fg.subtitle('This is a cool feed!')
|
||||
|
||||
#fg.language('en')
|
||||
|
||||
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]
|
||||
|
||||
#print(title)
|
||||
|
||||
link = i.find("a", href=True)['href']
|
||||
|
||||
#print(link)
|
||||
|
||||
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'):
|
||||
#print(p.get_text())
|
||||
content=content+p.get_text()
|
||||
|
||||
#print("-------",content)
|
||||
|
||||
fe = fg.add_entry()
|
||||
fe.id(link)
|
||||
fe.title(title)
|
||||
fe.pubDate(pubdate)
|
||||
fe.link(href=link)
|
||||
fe.content(content)
|
||||
|
||||
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
|
Loading…
Reference in new issue