From b9aea57c10d8336b13517f7f8c87ef5399b40b2e Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Thu, 5 Dec 2024 22:02:39 +0100 Subject: [PATCH] get the server from the environment --- mastodon-bot/fortunes-spam-bot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mastodon-bot/fortunes-spam-bot.py b/mastodon-bot/fortunes-spam-bot.py index 84cb2ae..56d224a 100755 --- a/mastodon-bot/fortunes-spam-bot.py +++ b/mastodon-bot/fortunes-spam-bot.py @@ -6,9 +6,6 @@ import sys import subprocess from mastodon import Mastodon -API_URL = 'https://botsin.space/' - - def getSpam(sections=('spam-o', 'spam-ita-o')): cmd = ['fortune', '-o', *sections] process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -26,10 +23,10 @@ def getSpam(sections=('spam-o', 'spam-ita-o')): return stdout -def serve(token): +def serve(api_url, token): spam = getSpam() print('serving:\n%s' % spam) - mastodon = Mastodon(access_token=token, api_base_url=API_URL) + mastodon = Mastodon(access_token=token, api_base_url=api_url) mastodon.status_post(spam, sensitive=True, spoiler_text='NSFW') @@ -37,4 +34,7 @@ if __name__ == '__main__': if 'SPAMBOT_TOKEN' not in os.environ: print("Please specify the Mastodon token in the SPAMBOT_TOKEN environment variable") sys.exit(1) - serve(token=os.environ['SPAMBOT_TOKEN']) + if 'API_URL' not in os.environ: + print("Please specify the Mastodon server in the API_URL environment variable") + sys.exit(1) + serve(api_url=os.environ['API_URL'], token=os.environ['SPAMBOT_TOKEN'])