mastodon bot

This commit is contained in:
Davide Alberani 2018-12-15 13:13:10 +01:00
parent 286a957563
commit 12196062ab
2 changed files with 53 additions and 0 deletions

23
Dockerfile Normal file
View file

@ -0,0 +1,23 @@
FROM alpine
LABEL \
maintainer="Davide Alberani <da@erlug.linux.it>"
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"]

30
mastodon-cthulhusay.py Executable file
View file

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