use confparser to get pleroma's options

This commit is contained in:
n 2021-02-07 17:30:54 +01:00
parent acc98829cc
commit 4a3e3664ad
Signed by: n
GPG key ID: 510227DD6C502CE3
3 changed files with 34 additions and 9 deletions

View file

@ -34,6 +34,7 @@ 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
from feed2toot.confparsers.pleroma import parsepleroma
from feed2toot.confparsers.plugins import parseplugins
from feed2toot.confparsers.rss.ignoressl import parseignoressl
from feed2toot.confparsers.rss.pattern import parsepattern
@ -113,6 +114,10 @@ class ConfParse:
###########################
options['media'] = parsemedia(config)
###########################
# the pleroma section
###########################
options['mastodon_feature_set'], options['toot_content_type'] = parsepleroma(config)
###########################
# the plugins section
###########################
plugins = parseplugins(config)

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Copyright © 2015-2020 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 pleroma section
'''Get values of the pleroma section'''
def parsepleroma(config):
'''Parse configuration values and get values of the pleroma section'''
mastodon_feature_set = 'mainline'
toot_content_type = None
if 'pleroma' in config.sections():
mastodon_feature_set = 'pleroma'
toot_content_type = config.get('pleroma', 'content_type', fallback='text/plain')
return mastodon_feature_set,toot_content_type

View file

@ -31,24 +31,18 @@ class TootPost:
def main(self):
'''Main of the TweetPost class'''
mastodon_feature_set = 'mainline'
toot_content_type = None
if 'pleroma' in self.config.sections():
mastodon_feature_set='pleroma'
if self.config.has_option('pleroma', 'content_type'):
toot_content_type=self.config.get('pleroma', 'content_type', fallback='text/plain')
mastodon = Mastodon(
client_id=self.config.get('mastodon', 'client_credentials'),
access_token=self.config.get('mastodon', 'user_credentials'),
api_base_url=self.config.get('mastodon', 'instance_url'),
feature_set=mastodon_feature_set
feature_set=self.options['mastodon_feature_set']
)
toot_visibility = self.config.get('mastodon', 'toot_visibility', fallback='public')
if 'custom' in self.options['media']:
mediaid = mastodon.media_post(self.config['media']['custom'])
mastodon.status_post(self.toot, media_ids=[mediaid], visibility=toot_visibility, content_type=toot_content_type)
mastodon.status_post(self.toot, media_ids=[mediaid], visibility=toot_visibility, content_type=self.options['toot_content_type'])
else:
mastodon.status_post(self.toot, visibility=toot_visibility, content_type=toot_content_type)
mastodon.status_post(self.toot, visibility=toot_visibility, content_type=self.options['toot_content_type'])
def storeit(self):
'''Indicate if the tweet should be stored or not'''