diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..30b9804 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM alpine +LABEL \ + maintainer="Davide Alberani " + +RUN \ + apk add --no-cache \ + python3 \ + py3-cffi \ + py3-six \ + py3-requests \ + py3-tz \ + py3-dateutil \ + py3-decorator \ + py3-cryptography && \ + pip3 install Mastodon.py +COPY cthulhusay.py mastodon-cthulhusay.py / +RUN chmod +x /mastodon-cthulhusay.py + +WORKDIR / + +ENTRYPOINT ["python3", "/mastodon-cthulhusay.py"] + + diff --git a/mastodon-cthulhusay.py b/mastodon-cthulhusay.py new file mode 100755 index 0000000..75fa3fe --- /dev/null +++ b/mastodon-cthulhusay.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import sys +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) + + +def get_words_of_cthulhu(): + return cthulhusay.cthulhu_say(words=random.randint(1, 25)) + + +def serve(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.status_post(words_of_cthulhu) + + +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'])