Add commandline argument to disable Mastodon

This commit is contained in:
Jessica L. Hacker 2019-09-19 09:44:52 -07:00
parent bebb4947fc
commit 3ce1fd3603

View file

@ -1,22 +1,27 @@
#!/usr/bin/python3
import os
from mastodon import Mastodon
import csv
import itertools
import random
import os
import argparse
instance = os.environ['MASTODON_INSTANCE']
username = os.environ['MASTODON_USERNAME']
parser = argparse.ArgumentParser(description='Parse quotes from .csv files, and post a random quote to Mastodon API')
parser.add_argument('--debug', action='store_true', help='Dont actually login or post to the remote API')
parser.add_argument('--nomastodon', action='store_true', help='Run without loading anything that requires the Mastodon library')
args = parser.parse_args()
instance = ""
username = ""
if not args.nomastodon:
from mastodon import Mastodon
instance = os.environ['MASTODON_INSTANCE']
username = os.environ['MASTODON_USERNAME']
mastodon_api = None
if not args.debug:
if not args.debug and not args.nomastodon:
# Create application if it does not exist
# TODO: store this file in volume
if not os.path.isfile(instance+'.secret'):
@ -58,5 +63,5 @@ row = random.choice(quotes)
text = '<p>{}</p>&nbsp;&nbsp;&nbsp;&nbsp;- {}, <a href={}>{}</a>'.format(row[0], row[1], row[2], row[3])
print(text)
if not args.debug:
if not args.debug and not args.nomastodon:
mastodon_api.status_post(text, visibility='public', content_type='text/html')