From 4608c57ea861e86f2bbae26dc55169f7c33e5ab4 Mon Sep 17 00:00:00 2001 From: "Sean B. Palmer" Date: Sat, 15 Jan 2011 14:52:37 +0000 Subject: [PATCH] Generic error message for services that don't return plain text. --- modules/oblique.py | 7 ++++++- modules/tell.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/oblique.py b/modules/oblique.py index e53ec29..3622b4a 100755 --- a/modules/oblique.py +++ b/modules/oblique.py @@ -34,10 +34,15 @@ def service(phenny, input, command, args): template = template.replace('${nick}', urllib.quote(input.nick)) uri = template.replace('${sender}', urllib.quote(input.sender)) + info = web.head(uri) + if isinstance(info, list): + info = info[0] + if not 'text/plain' in info.get('content-type', '').lower(): + return phenny.reply("Sorry, the service didn't respond in plain text.") bytes = web.get(uri) lines = bytes.splitlines() if not lines: - return phenny.reply('Sorry, the service is broken.') + return phenny.reply("Sorry, the service didn't respond any output.") phenny.say(lines[0][:350]) def refresh(phenny): diff --git a/modules/tell.py b/modules/tell.py index 2f39986..741c58d 100755 --- a/modules/tell.py +++ b/modules/tell.py @@ -29,7 +29,8 @@ def loadReminders(fn): for line in f: line = line.strip() if line: - tellee, teller, verb, timenow, msg = line.split('\t', 4) + try: tellee, teller, verb, timenow, msg = line.split('\t', 4) + except ValueError: continue # @@ hmm result.setdefault(tellee, []).append((teller, verb, timenow, msg)) f.close() return result