Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Extending status command for multiple spaces #187

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lib/spaceapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ 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():
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, msg)
raise Exception()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ideally should throw a custom exception, not a generic one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it is a good idea. You can add this.

r = yield from resp.read()
ret.append(json.loads(r.decode('utf-8')))

return ret
4 changes: 2 additions & 2 deletions plugins/cccongress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this should catch only this custom exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it is a good idea. You can add this. But this is a PR for station-plugin, not cccongress.

bot.log.error(e)
return []

now = datetime.datetime.now(pytz.timezone('Europe/Berlin'))
Expand Down
12 changes: 7 additions & 5 deletions plugins/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ 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')
Expand Down