From 8af868bdfcee34297f84ca9d63edef33cceccc06 Mon Sep 17 00:00:00 2001 From: Jurkov Date: Thu, 26 Oct 2017 22:26:47 +0200 Subject: [PATCH 1/4] Extending status command for multiple spaces --- lib/spaceapi.py | 18 +++++++++++------- plugins/status.py | 14 ++++++++------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/spaceapi.py b/lib/spaceapi.py index 6818d54..729fd33 100644 --- a/lib/spaceapi.py +++ b/lib/spaceapi.py @@ -11,10 +11,14 @@ def spaceapi(bot, target=None): with aiohttp.Timeout(10): with aiohttp.ClientSession(loop=bot.loop) as session: - resp = yield from session.get(config['url']) - if resp.status != 200: - if target is not None: - bot.privmsg(target, "Error while retrieving spaceapi data") - raise Exception() - r = yield from resp.read() - return json.loads(r.decode('utf-8')) + ret = [] + for space_url in config['url'].split(): + resp = yield from session.get(space_url) + if resp.status != 200: + if target is not None: + bot.privmsg(target, "Error while retrieving spaceapi data" + space_url) + raise Exception() + r = yield from resp.read() + ret.append(json.loads(r.decode('utf-8'))) + + return ret diff --git a/plugins/status.py b/plugins/status.py index fe1ab9d..f0f9e04 100644 --- a/plugins/status.py +++ b/plugins/status.py @@ -13,12 +13,14 @@ def status(bot, mask, target, args): """ try: data = yield from spaceapi(bot, target) - - bot.privmsg(target, 'Space status:') - if data['state']['open']: - bot.privmsg(target, '\tThe space is open!') - else: - bot.privmsg(target, '\tThe space is closed!') + + for space_data in data: + bot.privmsg(target, 'Space status of ' + space_data['space'] + ':') + if space_data['state']['open']: + bot.privmsg(target, '\tThe space is open!') + else: + bot.privmsg(target, '\tThe space is closed!') + except Exception as e: bot.log.error(e) bot.privmsg(target, '\tError while retrieving space status') From 96b59c5b9799f0cc3b0592465832cee2f5c974a5 Mon Sep 17 00:00:00 2001 From: Jurkov Date: Thu, 26 Oct 2017 22:32:33 +0200 Subject: [PATCH 2/4] Travis CI fixes #1 --- lib/spaceapi.py | 6 ++++-- plugins/status.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/spaceapi.py b/lib/spaceapi.py index 729fd33..3993d3d 100644 --- a/lib/spaceapi.py +++ b/lib/spaceapi.py @@ -16,9 +16,11 @@ def spaceapi(bot, target=None): resp = yield from session.get(space_url) if resp.status != 200: if target is not None: - bot.privmsg(target, "Error while retrieving spaceapi data" + space_url) + bot.privmsg( + target, + "Error while retrieving spaceapi data" + space_url) raise Exception() r = yield from resp.read() ret.append(json.loads(r.decode('utf-8'))) - + return ret diff --git a/plugins/status.py b/plugins/status.py index f0f9e04..f7647d2 100644 --- a/plugins/status.py +++ b/plugins/status.py @@ -13,14 +13,14 @@ def status(bot, mask, target, args): """ try: data = yield from spaceapi(bot, target) - + for space_data in data: bot.privmsg(target, 'Space status of ' + space_data['space'] + ':') if space_data['state']['open']: bot.privmsg(target, '\tThe space is open!') else: bot.privmsg(target, '\tThe space is closed!') - + except Exception as e: bot.log.error(e) bot.privmsg(target, '\tError while retrieving space status') From 94def1b7b40404e26f8070d0a83f4d1478983150 Mon Sep 17 00:00:00 2001 From: Jurkov Date: Thu, 26 Oct 2017 22:35:28 +0200 Subject: [PATCH 3/4] Travis CI #2 --- lib/spaceapi.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/spaceapi.py b/lib/spaceapi.py index 3993d3d..6ee73ae 100644 --- a/lib/spaceapi.py +++ b/lib/spaceapi.py @@ -13,12 +13,11 @@ def spaceapi(bot, target=None): with aiohttp.ClientSession(loop=bot.loop) as session: ret = [] for space_url in config['url'].split(): + msg = "Error while retrieving spaceapi data" + space_url resp = yield from session.get(space_url) if resp.status != 200: if target is not None: - bot.privmsg( - target, - "Error while retrieving spaceapi data" + space_url) + bot.privmsg(target, msg) raise Exception() r = yield from resp.read() ret.append(json.loads(r.decode('utf-8'))) From b054b1732414cadea4bf97f1e827073155183704 Mon Sep 17 00:00:00 2001 From: Jurkov Date: Thu, 26 Oct 2017 22:43:03 +0200 Subject: [PATCH 4/4] Travis fix no one likes bare excepts - hope someone like this except --- plugins/cccongress.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/cccongress.py b/plugins/cccongress.py index 8e2c0c6..c128bd7 100644 --- a/plugins/cccongress.py +++ b/plugins/cccongress.py @@ -202,8 +202,8 @@ def _get_talk(bot, hall, slot=0): try: json_data = _get_json_data(bot) - except: - """Silently ignore errors""" + except Exception as e: + bot.log.error(e) return [] now = datetime.datetime.now(pytz.timezone('Europe/Berlin'))