You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.6 KiB

#!/usr/bin/env python3
# Copyright (C) 2019 @LynnearSoftware@lynnesbian.fedi.space
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from mastodon import Mastodon
import argparse, sys, traceback, json
import create
parser = argparse.ArgumentParser(description='Generate and post a toot.')
parser.add_argument('-s', '--simulate', dest='simulate', action='store_true',
help="Print the toot to stdout without posting it")
args = parser.parse_args()
cfg = json.load(open('config.json', 'r'))
toot = create.make_toot()
if not args.simulate:
client = Mastodon(
client_id=cfg['client']['id'],
client_secret=cfg['client']['secret'],
access_token=cfg['secret'],
api_base_url=cfg['site'])
try:
client.status_post(toot, visibility = 'unlisted', spoiler_text = cfg['cw'])
except Exception as err:
toot = "A fatal error occured.\n{}".format("\n".join(traceback.format_tb(sys.exc_info()[2])))
client.status_post(toot, visibility = 'unlisted', spoiler_text = "Error!")
print(toot)