From 02e61d68ad32bf2221d385e8fa5455cf704c9ec7 Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Thu, 27 Apr 2017 17:58:43 +0200 Subject: [PATCH] option [hashtaglist] section. fixes #5 --- docs/source/configure.rst | 11 ++++++++++- feed2toot/confparse.py | 11 ++++++----- feed2toot/main.py | 4 +++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/source/configure.rst b/docs/source/configure.rst index ce95ee0..38c963e 100644 --- a/docs/source/configure.rst +++ b/docs/source/configure.rst @@ -64,7 +64,16 @@ For the [rss] section: For the [hashtaglist] section: -- several_words_hashtags_list: a path to the file containing hashtags in two or more words. Absolute path is mandatory. By default Feed2toot adds a # before every words of a hashtag. +- several_words_hashtags_list: a path to the file containing hashtags in two or more words. Absolute path is mandatory. By default Feed2toot adds a # before every words of a hashtag. See documentation below for an example of this file. + +Example of the list of hash tags +================================ +The list of hash tags is a simple text file with one hash tag composed by several words on a single line:: + + free software community + open-source + +Instead of having #free #software #community or #open-source in the resulting toot, you will have #freesoftwarecommunity and #opensource. You only have to identify the hash tags you frequently use in your RSS feeds and put them in this file to have well formatted hash tags in your toots. List of rss feeds ================= diff --git a/feed2toot/confparse.py b/feed2toot/confparse.py index 56f67a6..1611fb7 100644 --- a/feed2toot/confparse.py +++ b/feed2toot/confparse.py @@ -191,12 +191,13 @@ class ConfParse(object): if not self.clioptions.hashtaglist: confoption = 'several_words_hashtags_list' if config.has_section(section): - options['hashtaglist'] = config.get(section, confoption) - options['hashtaglist'] = os.path.expanduser(options['hashtaglist']) - if not os.path.exists(options['hashtaglist']) or not os.path.isfile(options['hashtaglist']): - sys.exit('The path to the several_words_hashtags_list parameter is not valid: {hashtaglist}'.format(hashtaglist=options['hashtaglist'])) + if config.has_option(section, confoption): + options['hashtaglist'] = config.get(section, confoption) + options['hashtaglist'] = os.path.expanduser(options['hashtaglist']) + if not os.path.exists(options['hashtaglist']) or not os.path.isfile(options['hashtaglist']): + sys.exit('The path to the several_words_hashtags_list parameter is not valid: {hashtaglist}'.format(hashtaglist=options['hashtaglist'])) else: - options['hashtaglist'] = False + options['hashtaglist'] = '' ########################### # # the plugins section diff --git a/feed2toot/main.py b/feed2toot/main.py index ba5140e..2ddf17f 100755 --- a/feed2toot/main.py +++ b/feed2toot/main.py @@ -75,10 +75,12 @@ class Main(object): plugins = conf[4] # create link to the persistent list cache = FeedCache(options) - if options['hashtaglist']: + if 'hashtaglist' in options and options['hashtaglist']: severalwordshashtags = codecs.open(options['hashtaglist'], encoding='utf-8').readlines() severalwordshashtags = [i.rstrip('\n') for i in severalwordshashtags] + else: + severalwordshashtags = [] # reverse feed entries because most recent one should be sent as the last one in Mastodon for feed in feeds: # store the patterns by rss