mirror of
https://gitlab.com/chaica/feed2toot.git
synced 2024-11-23 20:11:09 +00:00
Merge branch 'mahescho-01' into 'master'
allowed toot formating and made tags optional See merge request chaica/feed2toot!13
This commit is contained in:
commit
273cb28e57
|
@ -37,6 +37,7 @@ from feed2toot.confparsers.rss.pattern import parsepattern
|
||||||
from feed2toot.confparsers.rss.toot import parsetoot
|
from feed2toot.confparsers.rss.toot import parsetoot
|
||||||
from feed2toot.confparsers.rss.uri import parseuri
|
from feed2toot.confparsers.rss.uri import parseuri
|
||||||
from feed2toot.confparsers.rss.urilist import parseurilist
|
from feed2toot.confparsers.rss.urilist import parseurilist
|
||||||
|
from feed2toot.confparsers.rss.addtags import parseaddtags
|
||||||
|
|
||||||
class ConfParse:
|
class ConfParse:
|
||||||
'''ConfParse class'''
|
'''ConfParse class'''
|
||||||
|
@ -68,6 +69,10 @@ class ConfParse:
|
||||||
# pattern and patter_case_sensitive format option
|
# pattern and patter_case_sensitive format option
|
||||||
#################################################
|
#################################################
|
||||||
options['patterns'], options['patternscasesensitive'] = parsepattern(config)
|
options['patterns'], options['patternscasesensitive'] = parsepattern(config)
|
||||||
|
###############################
|
||||||
|
# addtags option, default: True
|
||||||
|
###############################
|
||||||
|
options['addtags'] = parseaddtags(config)
|
||||||
#################
|
#################
|
||||||
# uri_list option
|
# uri_list option
|
||||||
#################
|
#################
|
||||||
|
|
34
feed2toot/confparsers/rss/addtags.py
Normal file
34
feed2toot/confparsers/rss/addtags.py
Normal 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
|
|
@ -22,6 +22,7 @@ import importlib
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
# app libraries imports
|
# app libraries imports
|
||||||
from feed2toot.addtags import AddTags
|
from feed2toot.addtags import AddTags
|
||||||
|
@ -128,11 +129,10 @@ class Main:
|
||||||
|
|
||||||
severalwordsinhashtag = False
|
severalwordsinhashtag = False
|
||||||
# lets see if the rss feed has hashtag
|
# lets see if the rss feed has hashtag
|
||||||
if 'tags' in entry:
|
if 'tags' in entry and options['addtags']:
|
||||||
hastags = True
|
hastags = True
|
||||||
else:
|
else:
|
||||||
hastags = False
|
hastags = False
|
||||||
|
|
||||||
if hastags:
|
if hastags:
|
||||||
rss['hashtags'] = []
|
rss['hashtags'] = []
|
||||||
for i, _ in enumerate(entry['tags']):
|
for i, _ in enumerate(entry['tags']):
|
||||||
|
@ -160,16 +160,12 @@ class Main:
|
||||||
# remove space from hashtag
|
# remove space from hashtag
|
||||||
nospace = nospace.replace(" ", "")
|
nospace = nospace.replace(" ", "")
|
||||||
rss['hashtags'].append('#{}'.format(nospace))
|
rss['hashtags'].append('#{}'.format(nospace))
|
||||||
|
# parse tweetfomat to elements
|
||||||
elements = []
|
elements = re.findall(r"\{(.*?)\}",tweetformat)
|
||||||
for i in tweetformat.split(' '):
|
# strip : from elements to allow string formating, eg. {title:.20}
|
||||||
tmpelement = ''
|
for i,s in enumerate(elements):
|
||||||
# if i is not an empty string
|
if s.find(':'):
|
||||||
if i:
|
elements[i] = s.split(':')[0]
|
||||||
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
|
|
||||||
fe = FilterEntry(elements, entry, options, feed['patterns'], feed['rssobject'], feed['feedname'])
|
fe = FilterEntry(elements, entry, options, feed['patterns'], feed['rssobject'], feed['feedname'])
|
||||||
entrytosend = fe.finalentry
|
entrytosend = fe.finalentry
|
||||||
if entrytosend:
|
if entrytosend:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user