From 0e2418ea20eb81ab74bf5e41ba835b0a54471c5a Mon Sep 17 00:00:00 2001 From: The Dod Date: Wed, 28 Jun 2017 19:40:01 +0300 Subject: [PATCH 1/4] Add config option to change toot visibility Some instances allow bots only if their toots are unlisted, in order to avoid flooding the public timeline (makes sense). --- README.md | 2 ++ docs/source/configure.rst | 2 ++ feed2toot/main.py | 12 ++++++++++-- feed2toot/tootpost.py | 4 +++- 4 files changed, 17 insertions(+), 3 deletions(-) mode change 100755 => 100644 feed2toot/main.py diff --git a/README.md b/README.md index 960f817..c59105d 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ Alternatively you can donate cryptocurrencies: instance_url=https://mastodon.social user_credentials=feed2toot_usercred.txt client_credentials=feed2toot_clientcred.txt + ; Default visibility is public, but you can override it + toot_visibility=unlisted [cache] cachefile=cache.db diff --git a/docs/source/configure.rst b/docs/source/configure.rst index 38c963e..db67c45 100644 --- a/docs/source/configure.rst +++ b/docs/source/configure.rst @@ -26,6 +26,8 @@ In order to configure Feed2toot, you need to create a feed2toot.ini file (or any ; Here you need the two files created by register_feed2toot_app user_credentials=/etc/feed2toot/credentials/feed2toot_usercred.txt client_credentials=/etc/feed2toot/credentials/feed2toot_clientcred.txt + ; Default visibility is public, but you can override it + toot_visibility=unlisted [cache] cachefile=/var/lib/feed2toot/feed2toot.db diff --git a/feed2toot/main.py b/feed2toot/main.py old mode 100755 new mode 100644 index 7869f0f..733bd49 --- a/feed2toot/main.py +++ b/feed2toot/main.py @@ -189,13 +189,21 @@ class Main(object): if clioptions.dryrun: if entrytosend: - logging.warning('Tweet should have been sent: {tweet}'.format(tweet=finaltweet)) + logging.warning('Would toot with visibility "{visibility}": {toot}'.format( + toot=finaltweet, + visibility=config.get( + 'mastodon', 'toot_visibility', + fallback='public'))) else: logging.debug('This rss entry did not meet pattern criteria. Should have not been sent') else: storeit = True if entrytosend and not clioptions.populate: - logging.debug('sending the following tweet:{tweet}'.format(tweet=finaltweet)) + logging.debug('Tooting with visibility "{visibility}": {toot}'.format( + toot=finaltweet, + visibility=config.get( + 'mastodon', 'toot_visibility', + fallback='public'))) twp = TootPost(config, finaltweet) storeit = twp.storeit() else: diff --git a/feed2toot/tootpost.py b/feed2toot/tootpost.py index bad5684..c40c4ee 100644 --- a/feed2toot/tootpost.py +++ b/feed2toot/tootpost.py @@ -44,7 +44,9 @@ class TootPost: access_token = self.config.get('mastodon', 'user_credentials'), api_base_url = self.config.get('mastodon', 'instance_url') ) - mastodon.toot(self.toot) + mastodon.status_post(self.toot, + visibility=self.config.get( + 'mastodon', 'toot_visibility', fallback='public')) def storeit(self): '''Indicate if the tweet should be stored or not''' From 8673a648531d988ac2eb4e06c88beed541f578e1 Mon Sep 17 00:00:00 2001 From: The Dod Date: Wed, 28 Jun 2017 21:03:02 +0300 Subject: [PATCH 2/4] Document `toot_visibility` --- docs/source/configure.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/source/configure.rst b/docs/source/configure.rst index db67c45..231d738 100644 --- a/docs/source/configure.rst +++ b/docs/source/configure.rst @@ -49,6 +49,10 @@ For the [mastodon] section: - instance_url: the url of your Mastodon instance - user_credentials: a file with the user credentials, generated by the command register_feed2toot_app - client_credentials: a file with the client credentials, generated by the command register_feed2toot_app +- toot_visibility: any of the valid options for the `visibility` field + [here](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#posting-a-new-status). + Default is `public`, but `unlisted` prevents flooding + the instance's public timeline (which is more polite). For the [cache] section: From 5e0b915935c788c343490b17a9acfc2520976619 Mon Sep 17 00:00:00 2001 From: The Dod Date: Wed, 28 Jun 2017 21:10:10 +0300 Subject: [PATCH 3/4] =?UTF-8?q?D'Oh.=20It's=20RST=20(not=20MD)=20?= =?UTF-8?q?=F0=9F=98=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/configure.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/source/configure.rst b/docs/source/configure.rst index 231d738..818e4fb 100644 --- a/docs/source/configure.rst +++ b/docs/source/configure.rst @@ -49,11 +49,13 @@ For the [mastodon] section: - instance_url: the url of your Mastodon instance - user_credentials: a file with the user credentials, generated by the command register_feed2toot_app - client_credentials: a file with the client credentials, generated by the command register_feed2toot_app -- toot_visibility: any of the valid options for the `visibility` field - [here](https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#posting-a-new-status). - Default is `public`, but `unlisted` prevents flooding +- toot_visibility: any of the valid options for the *visibility* field + `here`__. + Default is *public*, but *unlisted* prevents flooding the instance's public timeline (which is more polite). +__ https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#posting-a-new-status + For the [cache] section: - cachefile: the path to the cache file storing ids of already tweeted links. Absolute path is mandatory. This file should always use the .db extension. From 658b48571b4666955491f7a0ae6a3c9ba65fbd56 Mon Sep 17 00:00:00 2001 From: The Dod Date: Wed, 28 Jun 2017 21:21:27 +0300 Subject: [PATCH 4/4] Comment out `toot_visibility` in examples (to stress that it's optional) --- README.md | 4 ++-- docs/source/configure.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c59105d..033adf0 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ Alternatively you can donate cryptocurrencies: instance_url=https://mastodon.social user_credentials=feed2toot_usercred.txt client_credentials=feed2toot_clientcred.txt - ; Default visibility is public, but you can override it - toot_visibility=unlisted + ; Default visibility is public, but you can override it: + ; toot_visibility=unlisted [cache] cachefile=cache.db diff --git a/docs/source/configure.rst b/docs/source/configure.rst index 818e4fb..f354ce8 100644 --- a/docs/source/configure.rst +++ b/docs/source/configure.rst @@ -26,8 +26,8 @@ In order to configure Feed2toot, you need to create a feed2toot.ini file (or any ; Here you need the two files created by register_feed2toot_app user_credentials=/etc/feed2toot/credentials/feed2toot_usercred.txt client_credentials=/etc/feed2toot/credentials/feed2toot_clientcred.txt - ; Default visibility is public, but you can override it - toot_visibility=unlisted + ; Default visibility is public, but you can override it: + ; toot_visibility=unlisted [cache] cachefile=/var/lib/feed2toot/feed2toot.db