get the server from the environment

This commit is contained in:
Davide Alberani 2024-12-05 23:45:39 +01:00
parent 12196062ab
commit 8bebdb69e0
4 changed files with 12 additions and 9 deletions

View file

@ -1,18 +1,19 @@
FROM alpine
LABEL \
maintainer="Davide Alberani <da@erlug.linux.it>"
maintainer="Davide Alberani <da@mimante.net>"
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

View file

@ -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 <da@erlug.linux.it>
Copyright 2017 Davide Alberani <da@mimante.net>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View file

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""R'lyehian language generator. The one and only cthulhu-fhtagn-ator.
Copyright 2017 Davide Alberani <da@erlug.linux.it>
Copyright 2017 Davide Alberani <da@mimante.net>
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'",

View file

@ -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'])