This script allows you to post a message to Mastodon from the command line. It reads the message from the command line argument or standard input. It uses the Mastodon.py library to interact with the Mastodon API.
In order to use this script, you will need to register an application with your Mastodon instance and obtain an access token. Here are the general steps you will need to follow:
- Log in to your Mastodon account on the web.
- Go to the “settings” page.
- Click on the “Development” tab.
- Click on the “New Application” button.
- Fill in the form with the required information, such as the name of your application, its website, and a short description.
- Choose the permissions you want your application to have.
- Click the “Submit” button.
Once your application is registered, you will be given a client ID and client secret, as well as the access_token.
import sys
from Mastodon import Mastodon
# Create a Mastodon API client
mastodon = Mastodon(
access_token = 'YOUR_ACCESS_TOKEN',
api_base_url = 'https://your.mastodon.instance'
)
# Get the message to post
if len(sys.argv) > 1:
message = sys.argv[1]
else:
message = input("Enter the message to post: ")
# Post the message
mastodon.toot(message)
You can run the script by passing the message to post as the first argument, or it will ask you to enter the message if no argument passed.