feedrss-toot/feed2toot/tootpost.py

49 lines
1.9 KiB
Python
Raw Normal View History

2017-04-09 10:30:48 +02:00
# vim:ts=4:sw=4:ft=python:fileencoding=utf-8
2020-12-07 20:33:30 +01:00
# Copyright © 2015-2020 Carl Chenet <carl.chenet@ohmytux.com>
2017-04-09 10:30:48 +02:00
# 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/>
"""Checks an RSS feed and posts new entries to Mastodon."""
# 3rd party libraries imports
from mastodon import Mastodon
class TootPost:
'''TootPost class'''
2018-05-30 23:24:47 +02:00
def __init__(self, config, options, toot):
2017-04-09 10:30:48 +02:00
'''Constructore of the TootPost class'''
self.config = config
2018-05-30 23:24:47 +02:00
self.options = options
2017-04-09 10:30:48 +02:00
self.store = True
self.toot = toot
self.main()
def main(self):
'''Main of the TweetPost class'''
mastodon = Mastodon(
2017-08-01 16:57:08 +02:00
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')
2017-04-09 10:30:48 +02:00
)
2017-08-01 16:57:08 +02:00
toot_visibility = self.config.get('mastodon', 'toot_visibility', fallback='public')
2018-05-30 23:24:47 +02:00
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)
else:
mastodon.status_post(self.toot, visibility=toot_visibility)
2017-04-09 10:30:48 +02:00
def storeit(self):
'''Indicate if the tweet should be stored or not'''
return self.store