From 2db37270a74caff12e941b0b8220df461abf2370 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Mon, 26 Dec 2011 22:16:16 -0500 Subject: [PATCH] cleanup in fcc module --- modules/fcc.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/modules/fcc.py b/modules/fcc.py index a87cfd2..f7f5a5d 100644 --- a/modules/fcc.py +++ b/modules/fcc.py @@ -9,26 +9,29 @@ import web import json def fcc(phenny, input): - """.fcc - Look up a callsign issued by the FCC.""" + """.fcc - Look up a callsign issued by the FCC.""" - callsign = input.group(2) + callsign = input.group(2) + if not callsign: + phenny.say(".fcc - Look up a callsign issued by the FCC.") + return - try: - req = web.get("http://callook.info/{0}/json".format(web.quote(callsign))) - data = json.loads(req) - except (HTTPError, IOError, ValueError): - phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.") - return + try: + req = web.get("http://callook.info/{0}/json".format(web.quote(callsign))) + data = json.loads(req) + except (HTTPError, IOError, ValueError): + phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.") + return - if len(data) <= 0 or data['status'] == 'INVALID': - phenny.reply('No results found for {0}'.format(callsign)) - return + if len(data) <= 0 or data['status'] == 'INVALID': + phenny.reply('No results found for {0}'.format(callsign)) + return - response = "{0} - {1} - {2}".format(data['current']['callsign'], - data['name'], data['otherInfo']['ulsUrl']) - phenny.say(response) + response = "{0} - {1} - {2}".format(data['current']['callsign'], + data['name'], data['otherInfo']['ulsUrl']) + phenny.say(response) fcc.rule = (['fcc'], r'(.*)') if __name__ == '__main__': - print(__doc__.strip()) + print(__doc__.strip())