From 4484e4b95cdc31fef0c80010230a4271e25e1f9c Mon Sep 17 00:00:00 2001 From: Clemens Klug Date: Mon, 28 May 2018 14:47:56 +0200 Subject: [PATCH] use abstract base class --- src/sources.py | 9 ++++++--- src/targets.py | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sources.py b/src/sources.py index 716e3cb..172d063 100644 --- a/src/sources.py +++ b/src/sources.py @@ -1,13 +1,16 @@ 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): return status.timestamp + datetime.timedelta(days=1) < datetime.datetime.today() diff --git a/src/targets.py b/src/targets.py index cfcb7d0..91b3ebc 100644 --- a/src/targets.py +++ b/src/targets.py @@ -1,4 +1,5 @@ import logging +from abc import ABCMeta, abstractmethod import requests @@ -6,9 +7,10 @@ from matrix_client.client import MatrixClient as MatrixApiClient from matrix_client.errors import MatrixError -class Client: +class Client(metaclass=ABCMeta): + @abstractmethod def __init__(self): - raise NotImplementedError() + pass def post_image(self, file, name, content_type="image/png", targets=None): """Push to all targets"""