commit ef3fab1f9af7b52fdee12259db799c31415c9792 Author: Ben Harris Date: Mon Jan 20 16:25:30 2020 -0500 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb6431e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +toot.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..260d598 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# toot + +small client for tooting to mastodon + +supply a credential file with `--creds` (see toot.json.sample) + +`toot` will default to looking for a file named `toot.json` alongside +the executable. + diff --git a/toot b/toot new file mode 100755 index 0000000..bd0e0c0 --- /dev/null +++ b/toot @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +import json +import os +import sys + +import click +import emoji +from mastodon import Mastodon + +@click.command() +@click.argument('status', required=False) +@click.option('--creds', default=os.path.join(os.path.dirname(__file__), "toot.json")) +def toot(status, creds): + # get config + with open(creds) as f: + config = json.load(f) + + # set up connection to mastodon + mastodon = Mastodon( + client_id=config['client_id'], + client_secret=config['client_secret'], + access_token=config['access_token'], + api_base_url=config['base_url'], + ) + + # get status from argument or from stdin + if not status: + status = "".join(sys.stdin).strip() + + # replace shortcodes with emoji :thumbsup: + status = emoji.emojize(status, use_aliases=True) + + # check status length and post status + if len(status) > 500: + print("Status is too long, try again") + elif len(status) == 0: + print("Did you type a status?") + else: + print(mastodon.toot(status)["uri"]) + +if __name__=='__main__': + toot() + diff --git a/toot.json.sample b/toot.json.sample new file mode 100644 index 0000000..07bac57 --- /dev/null +++ b/toot.json.sample @@ -0,0 +1,7 @@ +{ + "client_id": "", + "client_secret": "", + "access_token": "", + "base_url": "https://tilde.zone" +} +