add no_tags_in_toot configuration parameter to remove hashtags from toot
This commit is contained in:
parent
86ca0f14b6
commit
b7430f3b10
|
@ -30,6 +30,7 @@ import feedparser
|
||||||
# feed2toot library imports
|
# feed2toot library imports
|
||||||
from feed2toot.confparsers.cache import parsecache
|
from feed2toot.confparsers.cache import parsecache
|
||||||
from feed2toot.confparsers.hashtaglist import parsehashtaglist
|
from feed2toot.confparsers.hashtaglist import parsehashtaglist
|
||||||
|
from feed2toot.confparsers.hashtags.nohashtags import parsenotagsintoot
|
||||||
from feed2toot.confparsers.feedparser import parsefeedparser
|
from feed2toot.confparsers.feedparser import parsefeedparser
|
||||||
from feed2toot.confparsers.lock import parselock
|
from feed2toot.confparsers.lock import parselock
|
||||||
from feed2toot.confparsers.media import parsemedia
|
from feed2toot.confparsers.media import parsemedia
|
||||||
|
@ -99,9 +100,10 @@ class ConfParse:
|
||||||
###########################
|
###########################
|
||||||
options['cachefile'], options['cache_limit'] = parsecache(self.clioptions.cachefile, config)
|
options['cachefile'], options['cache_limit'] = parsecache(self.clioptions.cachefile, config)
|
||||||
###########################
|
###########################
|
||||||
# the hashtag section
|
# the hashtaglist section
|
||||||
###########################
|
###########################
|
||||||
options['hashtaglist'] = parsehashtaglist(self.clioptions.hashtaglist, config)
|
options['hashtaglist'] = parsehashtaglist(self.clioptions.hashtaglist, config)
|
||||||
|
options['notagsintoot'] = parsenotagsintoot(config)
|
||||||
###########################
|
###########################
|
||||||
# the media section
|
# the media section
|
||||||
###########################
|
###########################
|
||||||
|
|
15
feed2toot/confparsers/hashtags/__init__.py
Normal file
15
feed2toot/confparsers/hashtags/__init__.py
Normal 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/>
|
26
feed2toot/confparsers/hashtags/nohashtags.py
Normal file
26
feed2toot/confparsers/hashtags/nohashtags.py
Normal 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
|
|
@ -116,7 +116,7 @@ class Main:
|
||||||
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:
|
||||||
finaltweet = build_message(entrytosend, tweetformat, rss, options['tootmaxlen'])
|
finaltweet = build_message(entrytosend, tweetformat, rss, options['tootmaxlen'], options['notagsintoot'])
|
||||||
if clioptions.dryrun:
|
if clioptions.dryrun:
|
||||||
send_message_dry_run(config, entrytosend, finaltweet)
|
send_message_dry_run(config, entrytosend, finaltweet)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -26,13 +26,15 @@ from feed2toot.addtags import AddTags
|
||||||
from feed2toot.removeduplicates import RemoveDuplicates
|
from feed2toot.removeduplicates import RemoveDuplicates
|
||||||
from feed2toot.tootpost import TootPost
|
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'''
|
'''populate the rss dict with the new entry'''
|
||||||
tweetwithnotag = tweetformat.format(**entrytosend)
|
tweetwithnotag = tweetformat.format(**entrytosend)
|
||||||
# replace line breaks
|
# replace line breaks
|
||||||
tootwithlinebreaks = tweetwithnotag.replace('\\n', '\n')
|
tootwithlinebreaks = tweetwithnotag.replace('\\n', '\n')
|
||||||
# remove duplicates from the final tweet
|
# remove duplicates from the final tweet
|
||||||
dedup = RemoveDuplicates(tootwithlinebreaks)
|
dedup = RemoveDuplicates(tootwithlinebreaks)
|
||||||
|
# only add tags if user wants to
|
||||||
|
if not notagsintoot:
|
||||||
# only append hashtags if they exist
|
# only append hashtags if they exist
|
||||||
# remove last tags if tweet too long
|
# remove last tags if tweet too long
|
||||||
if 'hashtags' in rss:
|
if 'hashtags' in rss:
|
||||||
|
@ -40,9 +42,11 @@ def build_message(entrytosend, tweetformat, rss, tootmaxlen):
|
||||||
finaltweet = addtag.finaltweet
|
finaltweet = addtag.finaltweet
|
||||||
else:
|
else:
|
||||||
finaltweet = dedup.finaltweet
|
finaltweet = dedup.finaltweet
|
||||||
|
else:
|
||||||
|
finaltweet = dedup.finaltweet
|
||||||
# strip html tags
|
# strip html tags
|
||||||
finaltweet = BeautifulSoup(finaltweet, 'html.parser').get_text()
|
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:
|
if len(finaltweet) > tootmaxlen:
|
||||||
return ''.join([finaltweet[0:-3], '...'])
|
return ''.join([finaltweet[0:-3], '...'])
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue