cleanup in fcc module

master
mutantmonkey 2011-12-26 22:16:16 -05:00
parent 3adb930db8
commit 2db37270a7
1 changed files with 18 additions and 15 deletions

View File

@ -9,26 +9,29 @@ import web
import json import json
def fcc(phenny, input): def fcc(phenny, input):
""".fcc <callsign> - Look up a callsign issued by the FCC.""" """.fcc <callsign> - Look up a callsign issued by the FCC."""
callsign = input.group(2) callsign = input.group(2)
if not callsign:
phenny.say(".fcc <callsign> - Look up a callsign issued by the FCC.")
return
try: try:
req = web.get("http://callook.info/{0}/json".format(web.quote(callsign))) req = web.get("http://callook.info/{0}/json".format(web.quote(callsign)))
data = json.loads(req) data = json.loads(req)
except (HTTPError, IOError, ValueError): except (HTTPError, IOError, ValueError):
phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.") phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.")
return return
if len(data) <= 0 or data['status'] == 'INVALID': if len(data) <= 0 or data['status'] == 'INVALID':
phenny.reply('No results found for {0}'.format(callsign)) phenny.reply('No results found for {0}'.format(callsign))
return return
response = "{0} - {1} - {2}".format(data['current']['callsign'], response = "{0} - {1} - {2}".format(data['current']['callsign'],
data['name'], data['otherInfo']['ulsUrl']) data['name'], data['otherInfo']['ulsUrl'])
phenny.say(response) phenny.say(response)
fcc.rule = (['fcc'], r'(.*)') fcc.rule = (['fcc'], r'(.*)')
if __name__ == '__main__': if __name__ == '__main__':
print(__doc__.strip()) print(__doc__.strip())