add [media] parameter and bump to 0.8
This commit is contained in:
parent
5af950ee30
commit
c548e0cecb
11 changed files with 68 additions and 7 deletions
|
@ -24,7 +24,7 @@ import os
|
|||
import os.path
|
||||
import sys
|
||||
|
||||
__version__ = '0.7'
|
||||
__version__ = '0.8'
|
||||
|
||||
class CliParse:
|
||||
'''CliParse class'''
|
||||
|
|
|
@ -31,6 +31,7 @@ import feedparser
|
|||
from feed2toot.confparsers.cache import parsecache
|
||||
from feed2toot.confparsers.hashtaglist import parsehashtaglist
|
||||
from feed2toot.confparsers.feedparser import parsefeedparser
|
||||
from feed2toot.confparsers.media import parsemedia
|
||||
from feed2toot.confparsers.plugins import parseplugins
|
||||
from feed2toot.confparsers.rss.pattern import parsepattern
|
||||
from feed2toot.confparsers.rss.toot import parsetoot
|
||||
|
@ -85,6 +86,10 @@ class ConfParse:
|
|||
###########################
|
||||
options['hashtaglist'] = parsehashtaglist(self.clioptions.hashtaglist, config)
|
||||
###########################
|
||||
# the media section
|
||||
###########################
|
||||
options['media'] = parsemedia(config)
|
||||
###########################
|
||||
# the plugins section
|
||||
###########################
|
||||
plugins = parseplugins(config)
|
||||
|
|
39
feed2toot/confparsers/media.py
Normal file
39
feed2toot/confparsers/media.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright © 2015-2017 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 media section
|
||||
'''Get values of the media section'''
|
||||
|
||||
# standard library imports
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
def parsemedia(config):
|
||||
'''Parse configuration values and get values of the media section'''
|
||||
mediaconf = {}
|
||||
section = 'media'
|
||||
####################################
|
||||
# media option
|
||||
####################################
|
||||
confoption = 'custom'
|
||||
if config.has_section(section):
|
||||
if config.has_option(section, confoption):
|
||||
media = config.get(section, confoption)
|
||||
media = os.path.expanduser(media)
|
||||
if not os.path.exists(media) or not os.path.isfile(media):
|
||||
sys.exit('The path to the custom parameter is not valid: {media}'.format(media=media))
|
||||
else:
|
||||
mediaconf[confoption] = media
|
||||
return mediaconf
|
|
@ -200,7 +200,7 @@ class Main:
|
|||
visibility=config.get(
|
||||
'mastodon', 'toot_visibility',
|
||||
fallback='public')))
|
||||
twp = TootPost(config, finaltweet)
|
||||
twp = TootPost(config, options, finaltweet)
|
||||
storeit = twp.storeit()
|
||||
else:
|
||||
logging.debug('populating RSS entry {}'.format(rss['id']))
|
||||
|
|
|
@ -21,9 +21,10 @@ from mastodon import Mastodon
|
|||
class TootPost:
|
||||
'''TootPost class'''
|
||||
|
||||
def __init__(self, config, toot):
|
||||
def __init__(self, config, options, toot):
|
||||
'''Constructore of the TootPost class'''
|
||||
self.config = config
|
||||
self.options = options
|
||||
self.store = True
|
||||
self.toot = toot
|
||||
self.main()
|
||||
|
@ -36,7 +37,11 @@ class TootPost:
|
|||
api_base_url=self.config.get('mastodon', 'instance_url')
|
||||
)
|
||||
toot_visibility = self.config.get('mastodon', 'toot_visibility', fallback='public')
|
||||
mastodon.status_post(self.toot, visibility=toot_visibility)
|
||||
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)
|
||||
|
||||
def storeit(self):
|
||||
'''Indicate if the tweet should be stored or not'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue