Added support for a config file

master
alciregi 3 years ago
parent a612175847
commit d61919c546

@ -1,30 +1,36 @@
from bs4 import BeautifulSoup
from datetime import datetime
import requests
from feedgen.feed import FeedGenerator
import requests
import configparser
import sys
if len(sys.argv) < 2:
print("Please specify a config file")
sys.exit(1)
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 = ""
configfile = sys.argv[1]
config = configparser.ConfigParser()
config.read(configfile)
options = config.options('CONFIG')
conf = {}
for opt in options:
conf[opt] = config.get('CONFIG', opt)
fg = FeedGenerator()
fg.id(url)
fg.title(feedtitle)
fg.subtitle(description)
fg.id(conf['url'])
fg.title(conf['feedtitle'])
fg.subtitle(conf['description'])
#fg.link(href=selflink, rel='self' )
fg.author( {'name': authorname,'email': authormail} )
fg.link(href=url, rel='alternate' )
fg.author( {'name': conf['authorname'],'email': conf['authormail']} )
fg.link(href=conf['url'], rel='alternate' )
#fg.logo('http://ex.com/logo.jpg')
#fg.subtitle('This is a cool feed!')
#fg.language('en')
page = requests.get(url)
page = requests.get(conf['url'])
soup = BeautifulSoup(page.content,features="lxml")
@ -61,5 +67,5 @@ for i in soup.find_all('article'):
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
# fg.atom_file(conf['destpath'], pretty=True) # Write the ATOM feed to a file
fg.rss_file(conf['destpath'], pretty=True) # Write the RSS feed to a file
Loading…
Cancel
Save