2018-10-08 18:11:51 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
from mastodon import Mastodon
|
2018-10-13 23:58:58 -07:00
|
|
|
import argparse, sys, traceback, json
|
2018-10-08 18:11:51 -07:00
|
|
|
import create
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Generate and post a toot.')
|
|
|
|
parser.add_argument('reply', metavar='reply', type=str, nargs='?',
|
|
|
|
help='ID of the status to reply to')
|
|
|
|
parser.add_argument('-s', '--simulate', dest='simulate', action='store_true',
|
|
|
|
help="Print the toot to stdout without posting it")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2018-10-25 07:35:25 -07:00
|
|
|
cfg = json.load(open('config.json'))
|
2018-10-08 18:11:51 -07:00
|
|
|
|
|
|
|
client = Mastodon(
|
2018-10-25 07:35:25 -07:00
|
|
|
client_id=cfg['client']['id'],
|
|
|
|
client_secret=cfg['client']['secret'],
|
|
|
|
access_token=cfg['secret'],
|
|
|
|
api_base_url=cfg['site'])
|
2018-10-08 18:11:51 -07:00
|
|
|
|
2018-10-31 22:27:03 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
toot = create.make_toot()
|
|
|
|
if not args.simulate:
|
|
|
|
try:
|
|
|
|
if toot['media'] != None:
|
|
|
|
mediaID = client.media_post(toot['media'], description = toot['toot'])
|
|
|
|
client.status_post(toot['toot'].replace("\n", " "),
|
|
|
|
media_ids = [mediaID], visibility = "unlisted")
|
|
|
|
else:
|
|
|
|
client.status_post(toot['toot'], visibility = 'unlisted')
|
|
|
|
except Exception as err:
|
|
|
|
toot = {
|
|
|
|
"toot":
|
|
|
|
"Mistress @lynnesbian@fedi.lynnesbian.space, something has gone terribly" \
|
|
|
|
+ " wrong! While attempting to post a toot, I received the following" \
|
|
|
|
+ " error:\n" + "\n".join(traceback.format_tb(sys.exc_info()[2]))
|
|
|
|
}
|
|
|
|
client.status_post(toot['toot'], visibility = 'unlisted', spoiler_text = "Error!")
|
|
|
|
print(toot['toot'])
|