add [media] parameter and bump to 0.8

This commit is contained in:
Carl Chenet 2018-05-30 23:24:47 +02:00
parent 5af950ee30
commit c548e0cecb
11 changed files with 68 additions and 7 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ feedlist
*.ini
*.txt
*.bck
*.png

View file

@ -1,3 +1,7 @@
## [0.8] - 2018-05-30
### Added
- add the custom parameter in [media] section to join a custom media with every toots
## [0.7] - 2017-09-26
### Changed
- fix issue while using uri_list

View file

@ -20,7 +20,7 @@ Alternatively you can donate cryptocurrencies:
[Installation Guide](http://feed2toot.readthedocs.org/en/latest/install.html)*
# tar zxvf feed2toot-0.7.tar.gz
# tar zxvf feed2toot-0.8.tar.gz
# cd feed2toot
# python3 setup.py install
# # or

View file

@ -47,6 +47,9 @@ In order to configure Feed2toot, you need to create a feed2toot.ini file (or any
[feedparser]
accept_bozo_exceptions=true
[media]
custom=/var/lib/feed2toot/media/logo.png
For the [mastodon] section:
- instance_url: the url of your Mastodon instance
@ -81,6 +84,10 @@ for the [feedparser] section:
- accept_bozo_exceptions: If set to true, feed2toot will accept malformed feeds, which are rejected by default.
For the [media] section:
- custom: the path to a media (should be supported by Mastodon) to be posted with every Mastodon post.
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::

View file

@ -25,7 +25,7 @@ Alternatively, Setuptools may be installed to a user-local path::
* Untar the tarball and go to the source directory with the following commands::
$ tar zxvf feed2toot-0.7.tar.gz
$ tar zxvf feed2toot-0.8.tar.gz
$ cd feed2toot
* Next, to install Feed2toot on your computer, type the following command with the root user::

View file

@ -24,7 +24,7 @@ import os
import os.path
import sys
__version__ = '0.7'
__version__ = '0.8'
class CliParse:
'''CliParse class'''

View file

@ -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)

View 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

View file

@ -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']))

View file

@ -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,6 +37,10 @@ class TootPost:
api_base_url=self.config.get('mastodon', 'instance_url')
)
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)
else:
mastodon.status_post(self.toot, visibility=toot_visibility)
def storeit(self):

View file

@ -30,7 +30,7 @@ CLASSIFIERS = [
setup(
name='feed2toot',
version='0.7',
version='0.8',
license='GNU GPL v3',
description='Parse rss feeds and send new posts to Mastodon',
long_description='Parse rss feeds and send new posts to the Mastodon social network',