phenny-1/modules/fcc.py

35 lines
821 B
Python
Raw Normal View History

2011-11-29 22:58:05 -05:00
#!/usr/bin/python3
"""
fcc.py - fcc callsign lookup
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
from urllib.error import HTTPError
import web
import json
2011-11-29 22:58:05 -05:00
def fcc(phenny, input):
""".fcc <callsign> - Look up a callsign issued by the FCC."""
callsign = input.group(2)
try:
req = web.get("http://callook.info/{0}/json".format(web.quote(callsign)))
2011-11-29 22:58:05 -05:00
except (HTTPError, IOError):
phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.")
return
data = json.loads(req)
if len(data) <= 0:
2011-11-29 22:58:05 -05:00
phenny.reply('No results found for {0}'.format(callsign))
return
response = "{0} - {1} - {2}".format(data['current']['callsign'],
data['name'], data['otherInfo']['ulsUrl'])
2011-11-29 22:58:05 -05:00
phenny.say(response)
fcc.rule = (['fcc'], r'(.*)')
if __name__ == '__main__':
print(__doc__.strip())