From 8bebdb69e0a0487aa5f1c7b4908949e33b135027 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Thu, 5 Dec 2024 23:45:39 +0100 Subject: [PATCH] get the server from the environment --- Dockerfile | 5 +++-- README.md | 2 +- cthulhusay.py | 3 ++- mastodon-cthulhusay.py | 11 ++++++----- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30b9804..5782f6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,19 @@ FROM alpine LABEL \ - maintainer="Davide Alberani " + maintainer="Davide Alberani " RUN \ apk add --no-cache \ python3 \ py3-cffi \ py3-six \ + py3-pip \ py3-requests \ py3-tz \ py3-dateutil \ py3-decorator \ py3-cryptography && \ - pip3 install Mastodon.py + pip3 install --break-system-packages Mastodon.py COPY cthulhusay.py mastodon-cthulhusay.py / RUN chmod +x /mastodon-cthulhusay.py diff --git a/README.md b/README.md index 1c82e1a..02659a8 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ You may be right. Here it is the JavaScript version: https://github.com/alberani ## License and copyright -Copyright 2017 Davide Alberani +Copyright 2017 Davide Alberani Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/cthulhusay.py b/cthulhusay.py index feca773..1879f86 100755 --- a/cthulhusay.py +++ b/cthulhusay.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """R'lyehian language generator. The one and only cthulhu-fhtagn-ator. -Copyright 2017 Davide Alberani +Copyright 2017 Davide Alberani Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ limitations under the License. import random # Summoned from https://www.yog-sothoth.com/wiki/index.php/R'lyehian +# New translator: https://www.naguide.com/call-of-cthulhu-rlyehian-language-guide/ WORDS = ["'ai", "'bthnk", "'fhalma", 'ah', 'athg', 'bug', "ch'", 'chtenff', 'ebumna', 'ee', 'ehye', 'ep', 'fhtagn', "fm'latgh", 'ftaghu', 'geb', 'gnaiih', "gof'nn", 'goka', 'gotha', "grah'n", "hafh'drn", 'hai', 'hlirgh', 'hrii', 'hupadgh', 'ilyaa', "k'yarnak", 'kadishtu', "kn'a", "li'hee", 'llll', 'lloig', "lw'nafh", "mnahn'", diff --git a/mastodon-cthulhusay.py b/mastodon-cthulhusay.py index 75fa3fe..2558d1b 100755 --- a/mastodon-cthulhusay.py +++ b/mastodon-cthulhusay.py @@ -7,8 +7,6 @@ import random import cthulhusay from mastodon import Mastodon -API_URL = 'https://botsin.space/' - sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1) @@ -16,10 +14,10 @@ def get_words_of_cthulhu(): return cthulhusay.cthulhu_say(words=random.randint(1, 25)) -def serve(token): +def serve(api_url, token): words_of_cthulhu = get_words_of_cthulhu() print('serving:\n%s' % words_of_cthulhu) - mastodon = Mastodon(access_token=token, api_base_url=API_URL) + mastodon = Mastodon(access_token=token, api_base_url=api_url) mastodon.status_post(words_of_cthulhu) @@ -27,4 +25,7 @@ if __name__ == '__main__': if 'CTHULHUBOT_TOKEN' not in os.environ: print("Please specify the Mastodon token in the CTHULHUBOT_TOKEN environment variable") sys.exit(1) - serve(token=os.environ['CTHULHUBOT_TOKEN']) + if 'API_URL' not in os.environ: + print("Please specify the Mastodon server in the API_URL environment variable") + sys.exit(2) + serve(api_url=os.environ['API_URL'], token=os.environ['CTHULHUBOT_TOKEN'])