allowed toot formating and made tags optional

This commit is contained in:
Matthias Henze 2018-09-12 10:53:13 +02:00
parent 1741b5321e
commit affc3b6d28
3 changed files with 47 additions and 12 deletions

View File

@ -37,6 +37,7 @@ from feed2toot.confparsers.rss.pattern import parsepattern
from feed2toot.confparsers.rss.toot import parsetoot
from feed2toot.confparsers.rss.uri import parseuri
from feed2toot.confparsers.rss.urilist import parseurilist
from feed2toot.confparsers.rss.addtags import parseaddtags
class ConfParse:
'''ConfParse class'''
@ -68,6 +69,10 @@ class ConfParse:
# pattern and patter_case_sensitive format option
#################################################
options['patterns'], options['patternscasesensitive'] = parsepattern(config)
###############################
# addtags option, default: True
###############################
options['addtags'] = parseaddtags(config)
#################
# uri_list option
#################

View File

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Copyright © 2015-2017 Carl Chenet <carl.chenet@ohmytux.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/
# Get value of the patterne option of rss section
'''Get value of the addtags option of the rss section'''
# standard library imports
import logging
import sys
def parseaddtags(config):
'''Parse configuration value of the addtags option of the rss section'''
addtags = True
section = 'rss'
if config.has_section(section):
if config.has_option(section, 'addtags'):
try:
addtags = config.getboolean(section, 'addtags')
except ValueError as err:
logging.warn(err)
addtags = True
return addtags

View File

@ -22,6 +22,7 @@ import importlib
import logging
import logging.handlers
import sys
import re
# app libraries imports
from feed2toot.addtags import AddTags
@ -128,11 +129,10 @@ class Main:
severalwordsinhashtag = False
# lets see if the rss feed has hashtag
if 'tags' in entry:
if 'tags' in entry and options['addtags']:
hastags = True
else:
hastags = False
if hastags:
rss['hashtags'] = []
for i, _ in enumerate(entry['tags']):
@ -160,16 +160,12 @@ class Main:
# remove space from hashtag
nospace = nospace.replace(" ", "")
rss['hashtags'].append('#{}'.format(nospace))
elements = []
for i in tweetformat.split(' '):
tmpelement = ''
# if i is not an empty string
if i:
if i.startswith('{') and i.endswith('}'):
tmpelement = i.strip('{}')
elements.append(tmpelement)
# match elements of the tweet format string with available element in the RSS feed
# parse tweetfomat to elements
elements = re.findall(r"\{(.*?)\}",tweetformat)
# strip : from elements to allow string formating, eg. {title:.20}
for i,s in enumerate(elements):
if s.find(':'):
elements[i] = s.split(':')[0]
fe = FilterEntry(elements, entry, options, feed['patterns'], feed['rssobject'], feed['feedname'])
entrytosend = fe.finalentry
if entrytosend: