Merge branch 'add-feedname' into 'master'

Add the ability to use {feedname} in the tweet template

See merge request !7
This commit is contained in:
Carl Chenet 2017-07-31 13:33:59 +00:00
commit 67b7e72507
4 changed files with 39 additions and 18 deletions

View file

@ -23,6 +23,7 @@ import os
import os.path
import socket
import sys
import re
# 3rd party library imports
import feedparser
@ -53,9 +54,9 @@ class ConfParse(object):
self.accept_bozo_exceptions = False
###########################
#
#
# the rss section
#
#
###########################
section = 'rss'
if config.has_section(section):
@ -108,6 +109,12 @@ class ConfParse(object):
for line in rsslist:
line = line.strip()
# split each line in two parts, rss link and a string with the different patterns to look for
feedname = None
if '<' in line:
matches = re.match('(.*) <(.*)>', line)
if not matches:
sys.exit('This line in the list of uri to parse is not formatted correctly: {line}'.format(line))
feedname, line = matches.groups()
confobjects = line.split('|')
if len(confobjects) > 3 or len(confobjects) == 2:
sys.exit('This line in the list of uri to parse is not formatted correctly: {line}'.format(line))
@ -132,7 +139,7 @@ class ConfParse(object):
sys.exit('The rss object {rssobject} could not be found in the feed {rss}'.format(rssobject=rssobject, rss=rss))
else:
sys.exit('The rss feed {rss} does not seem to be valid'.format(rss=rss))
feeds.append({'feed': feed, 'patterns': patterns, 'rssobject': rssobject})
feeds.append({'feed': feed, 'patterns': patterns, 'rssobject': rssobject, 'feedname': feedname})
# test if all feeds in the list were unsuccessfully retrieved and if so, leave
if not feeds and bozoexception:
sys.exit('No feed could be retrieved. Leaving.')
@ -161,9 +168,9 @@ class ConfParse(object):
if config.has_option(section, currentoption):
options['nopatternurinoglobalpattern'] = config.getboolean(section, currentoption)
###########################
#
#
# the cache section
#
#
###########################
section = 'cache'
if not self.clioptions.cachefile:
@ -191,9 +198,9 @@ class ConfParse(object):
else:
options['cache_limit'] = 100
###########################
#
#
# the hashtag section
#
#
###########################
section = 'hashtaglist'
if not self.clioptions.hashtaglist:
@ -207,9 +214,9 @@ class ConfParse(object):
else:
options['hashtaglist'] = ''
###########################
#
#
# the plugins section
#
#
###########################
plugins = {}
section = 'influxdb'
@ -236,7 +243,7 @@ class ConfParse(object):
self.confs.append((options, config, self.tweetformat, feeds, plugins))
else:
self.confs.append((options, config, self.tweetformat, [{'feed': feed, 'patterns': [], 'rssobject': ''}], plugins))
@property
def confvalues(self):
'''Return the values of the different configuration files'''