A small python 3.x script to replicate tweets on a mastodon account.
The script only need mastodon login/pass to post toots.
It gets the tweets using twint, then does some cleanup on the content:
- twitter tracking links (t.co) are dereferenced
- twitter hosted pictures or videos are retrieved with yt-dlp and uploaded to mastodon
It can also toot RSS/atom feeds (see cron-example.sh).
A sqlite database is used to keep track of tweets than have been tooted.
This script is in use for a few accounts:
- osm_fr -> https://fr.osm.social/@osm_fr
- sotmfr -> https://fr.osm.social/@sotmfr
- macbidouille -> https://amicale.net/@macbidouille
- nextinpact -> https://amicale.net/@nextinpact
- opendata -> https://amicale.net/@opendata
The script is simply called by a cron job and can run on any server (does not have to be on the mastodon instance server).
# clone this repo
git clone https://github.com/cquest/tootbot.git
cd tootbot
# install required python modules
pip3 install -r requirements.txt
# install additional required software
sudo apt install jq
python3 tootbot.py <twitter_pseudo> <mastodon_account> <mastodon_password> <mastodon_domain> [max_items [tags_to_add]]
Example:
python3 tootbot.py geonym_fr [email protected] **password** mastodon.mydomain.org
It's up to you to add this in your crontab :)
With a plain RSS/atom feed:
python3 tootbot.py https://www.data.gouv.fr/fr/datasets/recent.atom [email protected] **password** amicale.net 2 "#dataset #opendata #datagouvfr"