Compare commits

..

No commits in common. "master" and "matrix" have entirely different histories.

7 changed files with 16 additions and 24 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
settings.json settings.json
__pycache__/ __pycache__/
*.pyc *.pyc
*.png
.venv/

View File

@ -1,11 +1,8 @@
FROM python:3.6-alpine3.7 FROM python:3.6-alpine3.7
ADD ["src", "requirements.txt", "/app/"] ADD [".", "/app"]
WORKDIR /app WORKDIR /app
RUN apk add --update g++ gfortran openblas-dev libpng-dev musl-dev freetype-dev libpng openblas libstdc++ && \ RUN apk add --update g++ gfortran openblas-dev libpng-dev musl-dev freetype-dev
pip install -r requirements.txt --no-cache-dir && \ RUN pip install -r requirements.txt --no-cache-dir
apk del g++ gfortran openblas-dev libpng-dev musl-dev freetype-dev && \
useradd -D bot
USER bot
CMD ["python", "bot.py"] CMD ["python", "bot.py"]

View File

View File

@ -3,6 +3,6 @@ version: "2"
services: services:
doorbot: doorbot:
build: . build: .
image: fswiai/doorbot:0.4 image: fswiai/doorbot:0.2
volumes: volumes:
- ./settings.json:/app/settings.json - ./settings.json:/app/settings.json

View File

@ -1,19 +1,16 @@
import datetime import datetime
from abc import ABCMeta, abstractmethod
from collections import namedtuple
import requests import requests
from collections import namedtuple
Status = namedtuple("Status", ['doorstate', 'timestamp', 'text']) Status = namedtuple("Status", ['doorstate', 'timestamp', 'text'])
class Source(metaclass=ABCMeta): class Source:
@abstractmethod
def get_status(self): def get_status(self):
pass raise NotImplementedError()
def is_recent(self, status, **kwargs): def is_recent(self, status, **kwargs):
return status.timestamp + datetime.timedelta(days=1) < datetime.datetime.today() raise NotImplementedError()
class IsFsWIAIopen(Source): class IsFsWIAIopen(Source):
url = "https://isfswiaiopen.wiai.de?json" url = "https://isfswiaiopen.wiai.de?json"
@ -32,4 +29,7 @@ class IsFsWIAIopen(Source):
return Status( return Status(
doorstate=str(status['doorstate']), doorstate=str(status['doorstate']),
timestamp=self._parse_time(status['timestamp']), timestamp=self._parse_time(status['timestamp']),
text=self._get_text(str(status['doorstate']))) text=self._get_text(str(status['doorstate'])))
def is_recent(self, status, **kwargs):
return status.timestamp + datetime.timedelta(days=1) < datetime.datetime.today()

View File

@ -1,5 +1,4 @@
import logging import logging
from abc import ABCMeta, abstractmethod
import requests import requests
@ -7,21 +6,18 @@ from matrix_client.client import MatrixClient as MatrixApiClient
from matrix_client.errors import MatrixError from matrix_client.errors import MatrixError
class Client(metaclass=ABCMeta): class Client:
@abstractmethod
def __init__(self):
pass
def post_image(self, file, name, content_type="image/png", targets=None): def post_image(self, file, name, content_type="image/png", targets=None):
"""Push to all targets""" """Push to all targets"""
self.post_image(file, name, content_type, targets) self.post_image(file, name, content_type, targets)
#raise NotImplementedError()
def send_image(self, target, file, name, content_type="image/png"): def send_image(self, target, file, name, content_type="image/png"):
"""Send an image to a room """Send an image to a room
Args: Args:
target (str): The internal room id to post into target (str): The internal room id to post into
file (file): The image file object path (file): The image file object
name (str): The name for the file in the room name (str): The name for the file in the room
content_type (str): Content-type of the image content_type (str): Content-type of the image
""" """
@ -30,6 +26,7 @@ class Client(metaclass=ABCMeta):
def post_text(self, text, targets=None): def post_text(self, text, targets=None):
"""Push to all targets""" """Push to all targets"""
self.post_text(text, targets) self.post_text(text, targets)
#raise NotImplementedError()
def send_text(self, target, text): def send_text(self, target, text):
"""Send a text to a room """Send a text to a room