fixed to large image error

This commit is contained in:
2018-09-12 13:37:42 +02:00
parent 12d6bb4652
commit 3e2ff23770

View File

@@ -81,6 +81,8 @@ class NewsInformer(object):
self.logger.info('sending notification: %s', title) self.logger.info('sending notification: %s', title)
text = text.replace('<br>', '\n') text = text.replace('<br>', '\n')
try: try:
self.logger.info(text)
self.logger.info(title)
pushover.Client(self.pushover).send_message( pushover.Client(self.pushover).send_message(
text, text,
title=title, title=title,
@@ -381,8 +383,13 @@ class Infomentor(object):
r = self._do_get(url) r = self._do_get(url)
if r.status_code != 200: if r.status_code != 200:
return False return False
with open(filename, 'wb+') as f: from PIL import Image
f.write(r.content) from resizeimage import resizeimage
import io
si = io.BytesIO(r.content)
image = Image.open(si)
image = resizeimage.resize_width(image, 800)
image.save(filename, image.format)
return filename return filename
def get_calendar(self): def get_calendar(self):
@@ -519,12 +526,11 @@ def main():
now = datetime.datetime.now() now = datetime.datetime.now()
ni = NewsInformer(**user, logger=logger) ni = NewsInformer(**user, logger=logger)
statusinfo = {'username': user['username'], statusinfo = {'username': user['username'],
'date': now, 'ok': False, 'info': ''} 'date': now, 'ok': False, 'info': '', 'degraded_count':0}
try: try:
ni.notify_news() ni.notify_news()
statusinfo['ok'] = True statusinfo['ok'] = True
statusinfo['degraded'] = False statusinfo['degraded'] = False
statusinfo['info'] = 'Works as expected'
except Exception as e: except Exception as e:
inforstr = 'Exception occured:\n{}:{}\n'.format(type(e).__name__, e) inforstr = 'Exception occured:\n{}:{}\n'.format(type(e).__name__, e)
statusinfo['ok'] = False statusinfo['ok'] = False
@@ -536,9 +542,17 @@ def main():
if previous_status['ok'] == True and statusinfo['ok'] == False: if previous_status['ok'] == True and statusinfo['ok'] == False:
logger.error('Switching to degraded state %s', user['username']) logger.error('Switching to degraded state %s', user['username'])
statusinfo['degraded'] = True statusinfo['degraded'] = True
statusinfo['degraded_count'] = 1
if previous_status['degraded'] == True and statusinfo['ok'] == False: if previous_status['degraded'] == True and statusinfo['ok'] == False:
if statusinfo['degraded_count'] == 1:
send_status_update(user['pushover'], statusinfo['info']) send_status_update(user['pushover'], statusinfo['info'])
try:
statusinfo['degraded_count'] = previous_status['degraded_count'] + 1
except KeyError as e:
statusinfo['degraded_count'] = 1
if previous_status['degraded'] == True and statusinfo['ok'] == True: if previous_status['degraded'] == True and statusinfo['ok'] == True:
statusinfo['info'] = 'Works as expected, failed {} times'.format(previous_status['degraded_count'])
statusinfo['degraded_count'] = 0
send_status_update(user['pushover'], statusinfo['info']) send_status_update(user['pushover'], statusinfo['info'])
db_api_status.upsert(statusinfo, ['username']) db_api_status.upsert(statusinfo, ['username'])