Skip to content

Instantly share code, notes, and snippets.

@PetraOleum
Created May 30, 2020 00: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 PetraOleum/5ebe6f0cc238df56615d086fc061eb14 to your computer and use it in GitHub Desktop.
Save PetraOleum/5ebe6f0cc238df56615d086fc061eb14 to your computer and use it in GitHub Desktop.
Mastodon.py secret generation script
# Mastodon.py client setup
# Install mastodon module with pip install --user Mastodon.py or equiv
# See https://mastodonpy.readthedocs.io/en/stable/ for more information
from getpass import getpass
from mastodon import Mastodon
import argparse
parser = argparse.ArgumentParser(description = ("Generate secret file "
"for mastodon.py api"))
parser.add_argument("name", help="Name of app, e.g. mybot")
parser.add_argument("base_url", help=("Target domain, e.g. "
"\"https://mastodon.social\""))
parser.add_argument("email", help=("Email account is registered to, e.g. "
"\"bot@example.com\""))
args = parser.parse_args()
password = getpass()
Mastodon.create_app(
args.name,
api_base_url = args.base_url,
to_file = "{}_clientcred.secret".format(args.name)
)
mastodon = Mastodon(
client_id = "{}_clientcred.secret".format(args.name),
api_base_url = args.base_url
)
mastodon.log_in(
args.email,
password,
to_file = "{}_usercred.secret".format(args.name)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment