Compare commits

...

8 Commits

Author SHA1 Message Date
Clemens Klug 0b11b8d73c add user 2018-07-18 10:47:34 +02:00
Clemens Klug 4484e4b95c use abstract base class 2018-05-28 14:47:56 +02:00
Clemens Klug 310d236390 move sources to src/ 2018-04-16 14:04:23 +02:00
Clemens Klug 6df26b1e7c reduce size of image 2018-04-16 13:45:13 +02:00
Clemens Klug c5f5b151bd Merge branch 'matrix' into 'master'
Matrix

See merge request server/doorbot!1
2018-04-16 11:00:56 +00:00
Clemens Klug c7cb219584 Merge branch 'master' into 'matrix'
# Conflicts:
#   bot.py
2018-04-16 11:00:36 +00:00
agp8x 39fbb813ae Merge branch 'master' of clkl.de:wiai/doorbot 2018-04-11 19:19:18 +02:00
agp8x df11aef895 load text from config 2018-04-11 19:16:59 +02:00
7 changed files with 24 additions and 16 deletions

2
.gitignore vendored
View File

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

View File

@ -1,8 +1,11 @@
FROM python:3.6-alpine3.7
ADD [".", "/app"]
ADD ["src", "requirements.txt", "/app/"]
WORKDIR /app
RUN apk add --update g++ gfortran openblas-dev libpng-dev musl-dev freetype-dev
RUN pip install -r requirements.txt --no-cache-dir
RUN apk add --update g++ gfortran openblas-dev libpng-dev musl-dev freetype-dev libpng openblas libstdc++ && \
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"]

View File

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

View File

View File

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

View File

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