phenny-1/modules/fcc.py

36 lines
991 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 tools import GrumbleError
2011-11-29 22:58:05 -05:00
import web
import json
2011-11-29 22:58:05 -05:00
def fcc(phenny, input):
2011-12-26 22:16:16 -05:00
""".fcc <callsign> - Look up a callsign issued by the FCC."""
callsign = input.group(2)
if not callsign:
phenny.say(".fcc <callsign> - 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)
2013-06-09 01:27:24 -04:00
except:
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
2011-12-26 22:16:16 -05:00
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)
2011-11-29 22:58:05 -05:00
fcc.rule = (['fcc'], r'(.*)')
if __name__ == '__main__':
2011-12-26 22:16:16 -05:00
print(__doc__.strip())