diff --git a/bot.py b/bot.py index f17810f..beab2e4 100644 --- a/bot.py +++ b/bot.py @@ -8,7 +8,7 @@ import logging import requests import schedule -logging.basicConfig(format='%(levelname)s %(name)s:%(message)s', level=logging.DEBUG) +logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s:%(message)s', level=logging.DEBUG, datefmt="%Y.%m.%d %H:%M:%S") log = logging.getLogger(__name__) def parse_time(string): @@ -73,7 +73,11 @@ def post_plot(config): from plot import get_plot with NamedTemporaryFile() as target: image_url = 'https://api.telegram.org/bot{token}/sendPhoto'.format(token=config['token']) - files = {'photo': get_plot(target)} + photo, last = get_plot(target) + files = {'photo': photo} + if last + datetime.timedelta(days=1) < datetime.datetime.today(): + log.info("skipping image, no new updates...") + return for chat in config['groups']: files['photo'].seek(0) values = {"chat_id":config['groups'][chat]} diff --git a/plot.py b/plot.py index a436471..886375e 100644 --- a/plot.py +++ b/plot.py @@ -49,7 +49,7 @@ def plot(raw, target="wiai.png"): plt.figtext(0.5, 0.25, "created: "+str(date.today()), ha="center") plt.figtext(0.5, 0.2, str(first[0])+" → "+str(last[0]), ha="center") plt.savefig(target, format="PNG", transparent=True, bbox_inches="tight") - return target + return target, last[0] def local(target): @@ -59,7 +59,7 @@ def local(target): def prod(target): - plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target) + return plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target) def get_plot(target): return plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target)