Skip to content

Instantly share code, notes, and snippets.

@zkg
Last active January 3, 2024 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkg/30d0c02eabb36b976f706f9c36e22f59 to your computer and use it in GitHub Desktop.
Save zkg/30d0c02eabb36b976f706f9c36e22f59 to your computer and use it in GitHub Desktop.
Automatically boost a Mastodon posts from a given user
# mastodon_booster.py
# Instructions:
# 1) Create a Mastodon application from the Developer settings of your instance.
# 2) Save the access token in a token.secret file, along with this file, on your server.
# 3) Adjust the path to token.secret, the api_base_url and the account_username you want to automatically boost.
# 4) Configure your crond to run this script every hour. A way to do that is using the crontab -e command.
# Add this line:
# 30 * * * * /usr/bin/python3 /path/to/your/script.py >/dev/null 2>&1
# You may decide to use a different frequency. If you do, make sure to edit also the timedelta on line 32.
# If you do so, be mindful that frequent automatic boosting might be regarded as spammy behavior by some Mastodon
# instances and thus can get your account suspended. Please, read and comply with the rules of your instance.
from mastodon import Mastodon
from datetime import datetime, timedelta, timezone
mastodon = Mastodon(
access_token = "/path/to/token.secret",
api_base_url = "https://your-instance-url.com"
)
account_username = "target-username"
def boost_toots():
account_info = mastodon.account_search(account_username, limit=1)
if account_info:
account_id = account_info[0]['id']
toots = mastodon.account_statuses(account_id)
for toot in toots:
created_at = toot['created_at']
if created_at > datetime.now(tz=timezone.utc) - timedelta(hours=1):
mastodon.status_reblog(toot['id'])
if __name__ == "__main__":
boost_toots()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment