add no_tags_in_toot configuration parameter to remove hashtags from toot

This commit is contained in:
Carl Chenet 2019-12-30 22:35:05 +01:00
parent 86ca0f14b6
commit b7430f3b10
5 changed files with 56 additions and 9 deletions

View File

@ -30,6 +30,7 @@ import feedparser
# feed2toot library imports
from feed2toot.confparsers.cache import parsecache
from feed2toot.confparsers.hashtaglist import parsehashtaglist
from feed2toot.confparsers.hashtags.nohashtags import parsenotagsintoot
from feed2toot.confparsers.feedparser import parsefeedparser
from feed2toot.confparsers.lock import parselock
from feed2toot.confparsers.media import parsemedia
@ -99,9 +100,10 @@ class ConfParse:
###########################
options['cachefile'], options['cache_limit'] = parsecache(self.clioptions.cachefile, config)
###########################
# the hashtag section
# the hashtaglist section
###########################
options['hashtaglist'] = parsehashtaglist(self.clioptions.hashtaglist, config)
options['notagsintoot'] = parsenotagsintoot(config)
###########################
# the media section
###########################

View File

@ -0,0 +1,15 @@
#!/usr/bin/env python3
# vim:ts=4:sw=4:ft=python:fileencoding=utf-8
# Copyright © 2017-2019 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/>

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Copyright © 2015-2019 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 values of the no_tags_in_toot option of the hashtaglist section
'''Get values of the no_tags_in_toot option of the hashtaglist section'''
def parsenotagsintoot(config):
'''Parse configuration values and get values of the the no_tags_in_toot option of the hashtaglist section'''
section = 'hashtaglist'
option = 'no_tags_in_toot'
notagsintoot = False
if config.has_option(section, option):
notagsintoot = config.getboolean(section, option)
return notagsintoot

View File

@ -116,7 +116,7 @@ class Main:
fe = FilterEntry(elements, entry, options, feed['patterns'], feed['rssobject'], feed['feedname'])
entrytosend = fe.finalentry
if entrytosend:
finaltweet = build_message(entrytosend, tweetformat, rss, options['tootmaxlen'])
finaltweet = build_message(entrytosend, tweetformat, rss, options['tootmaxlen'], options['notagsintoot'])
if clioptions.dryrun:
send_message_dry_run(config, entrytosend, finaltweet)
else:

View File

@ -26,23 +26,27 @@ from feed2toot.addtags import AddTags
from feed2toot.removeduplicates import RemoveDuplicates
from feed2toot.tootpost import TootPost
def build_message(entrytosend, tweetformat, rss, tootmaxlen):
def build_message(entrytosend, tweetformat, rss, tootmaxlen, notagsintoot):
'''populate the rss dict with the new entry'''
tweetwithnotag = tweetformat.format(**entrytosend)
# replace line breaks
tootwithlinebreaks = tweetwithnotag.replace('\\n', '\n')
# remove duplicates from the final tweet
dedup = RemoveDuplicates(tootwithlinebreaks)
# only append hashtags if they exist
# remove last tags if tweet too long
if 'hashtags' in rss:
addtag = AddTags(dedup.finaltweet, rss['hashtags'])
finaltweet = addtag.finaltweet
# only add tags if user wants to
if not notagsintoot:
# only append hashtags if they exist
# remove last tags if tweet too long
if 'hashtags' in rss:
addtag = AddTags(dedup.finaltweet, rss['hashtags'])
finaltweet = addtag.finaltweet
else:
finaltweet = dedup.finaltweet
else:
finaltweet = dedup.finaltweet
# strip html tags
finaltweet = BeautifulSoup(finaltweet, 'html.parser').get_text()
# truncate toot to user-defined value
# truncate toot to user-defined value whatever the content is
if len(finaltweet) > tootmaxlen:
return ''.join([finaltweet[0:-3], '...'])
else: