2020-04-05 08:37:54 +00:00
|
|
|
# Twoot
|
|
|
|
|
2022-12-11 10:15:50 +00:00
|
|
|
Twoot is a python script that mirrors tweets from a twitter account to a Mastodon account.
|
|
|
|
It is simple to set-up on a local machine, configurable and feature-rich.
|
|
|
|
|
2023-07-14 18:14:16 +00:00
|
|
|
**14 JUL 2023** VERSION 4.2
|
2023-06-19 18:03:21 +00:00
|
|
|
|
2023-07-14 18:14:16 +00:00
|
|
|
Twoot can now handle threads. All tweets can again be uploaded on Mastodon. Tweets in a threads are
|
|
|
|
displayed in reverse chronological order in the main timeline (first tweet on top) to improve readability.
|
2023-07-12 12:56:49 +00:00
|
|
|
|
2023-07-14 18:14:16 +00:00
|
|
|
*When several toots are posted in the same run of toot it is possible that these toots do not appear in
|
|
|
|
chronological order on the timeline. If it is the case, try setting `upload_pause` to 3-5 seconds in
|
|
|
|
your config file to slow down the rate at which toots are uploaded.*
|
|
|
|
|
|
|
|
A list of nitter instances to use can now be specified in the config file
|
|
|
|
e.g. `nitter_instances = ["nitter.nl", "nitter.fdn.fr"]`.
|
2023-07-14 18:42:06 +00:00
|
|
|
If none is specified, the built-in list of 2-3 known good instances is used as before.
|
2023-07-11 19:10:39 +00:00
|
|
|
|
2022-11-15 10:52:13 +00:00
|
|
|
> Previous updates can be found in CHANGELOG.
|
2020-02-15 15:06:15 +00:00
|
|
|
|
2022-09-14 15:02:48 +00:00
|
|
|
## Features
|
2019-08-01 14:03:24 +00:00
|
|
|
|
2022-11-15 10:52:13 +00:00
|
|
|
* Fetch timeline of given user from twitter.com (through nitter instance)
|
|
|
|
* Scrape html and format tweets for post on mastodon
|
2019-08-01 14:03:24 +00:00
|
|
|
* Emojis supported
|
2020-03-28 10:33:38 +00:00
|
|
|
* Upload images from tweet to Mastodon
|
2022-11-15 10:52:13 +00:00
|
|
|
* Optionally upload videos from tweet to Mastodon
|
2019-08-01 14:03:24 +00:00
|
|
|
* Specify maximum age of tweet to be considered
|
|
|
|
* Specify minimum delay before considering a tweet for upload
|
|
|
|
* Remember tweets already tooted to prevent double posting
|
2023-06-19 18:03:21 +00:00
|
|
|
* Optionally update avatar and banner pictures on profile if changed
|
2020-03-28 10:33:38 +00:00
|
|
|
* Optionally post reply-to tweets on the mastodon account
|
2022-11-15 10:52:13 +00:00
|
|
|
* Optionally ignore retweets
|
2023-01-30 10:10:23 +00:00
|
|
|
* Optionally remove redirections (e.g. reveal destination of short URLs)
|
|
|
|
* Optionally remove trackers (UTM parameters) from URLs
|
|
|
|
* Optional domain substitution for Twitter, Youtube and Reddit domains (e.g. [Nitter](https://github.com/zedeus/nitter/wiki/Instances),
|
2022-12-11 10:28:44 +00:00
|
|
|
[Invidious](https://redirect.invidious.io/) and [teddit](https://teddit.net/) respectively)
|
2023-07-11 19:10:39 +00:00
|
|
|
* option to add timestamp of the original tweet to bottom of toot
|
2022-12-11 10:28:44 +00:00
|
|
|
* Optional footer line to add tags at bottom of toot
|
2023-01-30 10:10:23 +00:00
|
|
|
* Allows rate-limiting posts to Mastodon instance
|
2019-08-01 14:03:24 +00:00
|
|
|
|
2022-11-22 11:50:34 +00:00
|
|
|
## Usage
|
2019-08-01 14:03:24 +00:00
|
|
|
|
2022-12-11 10:15:50 +00:00
|
|
|
```sh
|
2023-06-19 18:03:21 +00:00
|
|
|
usage: twoot.py [-h] [-f <.toml config file>] [-t <twitter account>] [-i <mastodon instance>]
|
|
|
|
[-m <mastodon account>] [-p <mastodon password>] [-r] [-s] [-l] [-u] [-v] [-o] [-q]
|
|
|
|
[-a <max age (in days)>] [-d <min delay (in mins)>] [-c <max # of toots to post>]
|
2019-08-01 14:03:24 +00:00
|
|
|
```
|
|
|
|
|
2022-11-22 11:50:34 +00:00
|
|
|
## Arguments
|
2019-08-01 14:03:24 +00:00
|
|
|
|
2019-08-01 14:18:15 +00:00
|
|
|
Assuming that the Twitter handle is @SuperDuperBot and the Mastodon account
|
2023-06-19 18:14:57 +00:00
|
|
|
is `sd@example.com` on instance masto.space:
|
2022-12-11 10:15:50 +00:00
|
|
|
|
|
|
|
|Switch |Description | Example | Required |
|
|
|
|
|-------|--------------------------------------------------|--------------------|--------------------|
|
|
|
|
| -f | path of `.toml` file with configuration | `SuperDuper.toml` | No |
|
|
|
|
| -t | twitter account name without '@' | `SuperDuper` | If no config file |
|
|
|
|
| -i | Mastodon instance domain name | `masto.space` | If no config file |
|
|
|
|
| -m | Mastodon username | `sd@example.com` | If no config file |
|
|
|
|
| -p | Mastodon password | `my_Sup3r-S4f3*pw` | Once at first run |
|
|
|
|
| -v | Upload videos to Mastodon | *N/A* | No |
|
|
|
|
| -o | Do not add "Original tweet" line | *N/A* | No |
|
2023-06-19 18:03:21 +00:00
|
|
|
| -q | Update avatar and banner on profile if changed | *N/A* | No |
|
2022-12-11 10:15:50 +00:00
|
|
|
| -r | Post reply-to tweets (ignored by default) | *N/A* | No |
|
|
|
|
| -s | Skip retweets (posted by default) | *N/A* | No |
|
|
|
|
| -l | Remove link redirections | *N/A* | No |
|
|
|
|
| -u | Remove trackers from URLs | *N/A* | No |
|
|
|
|
| -a | Max. age of tweet to post (in days) | `5` | No |
|
|
|
|
| -d | Min. age before posting new tweet (in minutes) | `15` | No |
|
|
|
|
| -c | Max number of toots allowed to post (cap) | `1` | No |
|
2019-08-01 14:03:24 +00:00
|
|
|
|
2022-11-22 11:50:34 +00:00
|
|
|
## Notes
|
|
|
|
|
2022-12-11 10:15:50 +00:00
|
|
|
### Password
|
|
|
|
|
|
|
|
A password must be provided for the first run only. Once twoot has connected successfully to the
|
|
|
|
Mastodon host, an access token is saved in a `.secret` file named after the mastodon account,
|
|
|
|
and a password is no longer necessary (command-line switch `-p` is not longer required).
|
|
|
|
|
|
|
|
### Config file
|
|
|
|
|
|
|
|
A `default.toml` file is provided to be used as template. If `-f` is used to specify a config file
|
|
|
|
to use, all the other command-line parameters are ignored, except `-p` (password) if provided.
|
|
|
|
|
|
|
|
### Removing redirected links
|
|
|
|
|
2023-06-19 18:03:21 +00:00
|
|
|
`-l` (or `remove_link_redirections = true` in toml file) will follow every link included in the
|
|
|
|
tweet and replace them with the url that the resource is directly dowmnloaded from (if applicable).
|
|
|
|
e.g. bit.ly/xxyyyzz -> example.com
|
|
|
|
Every link visit can take up to 5 sec (timeout) depending on the responsiveness of the source
|
|
|
|
therefore this option will slow down tweet processing.
|
2022-11-22 11:50:34 +00:00
|
|
|
|
2023-06-19 18:03:21 +00:00
|
|
|
If you are interested by tracker removal (`-u`, `remove_trackers_from_urls = true`) you should
|
|
|
|
also select redirection removal as trackers are often hidden behind the redirection of a short URL.
|
2022-11-23 20:51:57 +00:00
|
|
|
|
2022-12-11 10:15:50 +00:00
|
|
|
### Uploading videos
|
|
|
|
|
2023-06-19 18:03:21 +00:00
|
|
|
When using the `-v` (`upload_videos = true`) switch consider:
|
2022-11-12 09:33:57 +00:00
|
|
|
|
2020-03-29 11:57:18 +00:00
|
|
|
* whether the copyright of the content that you want to cross-post allows it
|
|
|
|
* the storage / transfer limitations of the Mastodon instance that you are posting to
|
|
|
|
* the upstream bandwidth that you may consume on your internet connection
|
2020-03-28 10:33:38 +00:00
|
|
|
|
2023-06-19 18:03:21 +00:00
|
|
|
### Updating profile
|
|
|
|
|
|
|
|
If `-q` (`update_profile = true`) is specified, twoot will check if the avatar and banner pictures
|
|
|
|
have changed on the twitter page. This check compares the name of files used by twitter with the names
|
|
|
|
of the files that have been uploaded on Mastodon and if they differ both files are downloaded from
|
|
|
|
twitter and uploaded on Mastodon. The check is very fast if there is no update.
|
|
|
|
|
2023-07-11 19:10:39 +00:00
|
|
|
### Adding timestamp of original tweet to toot
|
|
|
|
|
|
|
|
Use `tweet_time_format` option in configuration file to specify the datetime format to display the date
|
|
|
|
at which the tweet was published next to the "Original tweet" link. Valid format specifiers are
|
|
|
|
the same as those used to format datetimes in python
|
2023-07-14 18:18:56 +00:00
|
|
|
(<https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior>).
|
2023-07-11 19:10:39 +00:00
|
|
|
e.g. `tweet_time_format = "(%d %b %Y %H:%M %Z)"`
|
|
|
|
|
|
|
|
An empty or missing `tweet_time_format` disables the display of the timestamp.
|
|
|
|
|
|
|
|
By default, dates are specified in UTC time zone. To convert the timestamp to another time zone,
|
|
|
|
use the `tweet_timezone` option in configuration file. Valid time zone names are those of the Olson time
|
2023-07-14 18:18:56 +00:00
|
|
|
zone database (<https://en.wikipedia.org/wiki/Tz_database>)
|
2023-07-11 19:10:39 +00:00
|
|
|
e.g. `tweet_timezone = "Europe/Paris"`
|
|
|
|
|
2022-12-11 10:15:50 +00:00
|
|
|
### Rate control
|
|
|
|
|
2019-08-01 14:03:24 +00:00
|
|
|
Default max age is 1 day. Decimal values are OK.
|
|
|
|
|
2019-08-01 14:13:41 +00:00
|
|
|
Default min delay is 0 minutes.
|
|
|
|
|
2022-11-12 09:47:37 +00:00
|
|
|
No limitation is applied to the number of toots uploaded if `-c` is not specified.
|
|
|
|
|
2022-11-22 11:50:34 +00:00
|
|
|
## Installation
|
2019-08-01 14:13:41 +00:00
|
|
|
|
2019-08-01 15:17:47 +00:00
|
|
|
Make sure python3 is installed.
|
2019-08-01 14:13:41 +00:00
|
|
|
|
2023-07-14 18:18:56 +00:00
|
|
|
Twoot depends on `requests`, `beautifulsoup4`, `Mastodon.py` and `pytz` python modules.
|
|
|
|
Additionally, if you are using a version of python < 3.11 you also need to install the `tomli` module.
|
2020-03-28 10:47:53 +00:00
|
|
|
|
2023-07-14 18:18:56 +00:00
|
|
|
**Only If you plan to download videos** with the `-v` switch, are additional dependencies required:
|
2022-09-14 15:02:48 +00:00
|
|
|
|
2022-11-03 16:00:12 +00:00
|
|
|
* Python module `youtube-dl2`
|
2022-11-12 09:33:57 +00:00
|
|
|
* [ffmpeg](https://ffmpeg.org/download.html) (installed with the package manager of your distribution)
|
2019-08-01 14:13:41 +00:00
|
|
|
|
2022-09-14 15:02:48 +00:00
|
|
|
```sh
|
2023-07-14 18:14:16 +00:00
|
|
|
pip install beautifulsoup4 Mastodon.py youtube-dl2 pytz
|
2020-03-29 11:57:18 +00:00
|
|
|
```
|
2022-09-14 15:02:48 +00:00
|
|
|
|
2019-08-01 15:17:47 +00:00
|
|
|
In your user folder, execute `git clone https://gitlab.com/jeancf/twoot.git`
|
|
|
|
to clone repo with twoot.py script.
|
|
|
|
|
|
|
|
Add command line to crontab. For example, to run every 15 minutes starting at minute 1 of every hour
|
2019-08-01 14:13:41 +00:00
|
|
|
and process the tweets posted in the last 5 days but at least 15 minutes
|
|
|
|
ago:
|
|
|
|
|
2022-12-11 10:15:50 +00:00
|
|
|
```crontab
|
|
|
|
1-59/15 * * * * /path/to/twoot.py -t SuperDuper -i masto.space -m sd@example.com -p my_Sup3r-S4f3*pw -a 5 -d 15
|
2020-02-15 15:06:15 +00:00
|
|
|
```
|
2020-12-19 09:30:19 +00:00
|
|
|
|
2023-01-30 14:23:32 +00:00
|
|
|
## Featured Accounts
|
2022-11-13 20:44:08 +00:00
|
|
|
|
|
|
|
Twoot is known to be used for the following feeds (older first):
|
|
|
|
|
2023-01-30 14:23:32 +00:00
|
|
|
* [@todayilearned@noc.social](https://noc.social/@todayilearned)
|
2022-11-13 20:44:08 +00:00
|
|
|
* [@moznews@noc.social](https://noc.social/@moznews)
|
|
|
|
* [@hackster_io@noc.social](https://noc.social/@hackster_io)
|
|
|
|
* [@cnxsoft@noc.social](https://noc.social/@cnxsoft)
|
|
|
|
* [@unrealengine@noc.social](https://noc.social/@unrealengine)
|
|
|
|
* [@phoronix@noc.social](https://noc.social/@phoronix)
|
|
|
|
* [@uanews@fed.celp.de](https://fed.celp.de/@uanews)
|
2023-01-30 14:23:32 +00:00
|
|
|
* [@theregister@geeknews.chat](https://geeknews.chat/@theregister)
|
|
|
|
* [@arstechnica@geeknews.chat](https://geeknews.chat/@arstechnica)
|
|
|
|
* [@slashdot@geeknews.chat](https://geeknews.chat/@slashdot)
|
2022-11-13 20:44:08 +00:00
|
|
|
|
2022-09-14 15:02:48 +00:00
|
|
|
## Background
|
|
|
|
|
2023-01-30 14:23:32 +00:00
|
|
|
I started twoot when [tootbot](https://github.com/cquest/tootbot) stopped working.
|
|
|
|
Tootbot relied on RSS feeds from [https://twitrss.me](https://twitrss.me) that broke when Twitter
|
2022-12-11 10:15:50 +00:00
|
|
|
refreshed their web UI in July 2019.
|