From 5e3f24fadb96b3f2c8d738334ef03b5e013f5320 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Tue, 29 Nov 2011 22:58:05 -0500 Subject: [PATCH] add fcc callsign lookup --- modules/fcc.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 modules/fcc.py diff --git a/modules/fcc.py b/modules/fcc.py new file mode 100755 index 0000000..c6f62d1 --- /dev/null +++ b/modules/fcc.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 +""" +fcc.py - fcc callsign lookup +author: mutantmonkey +""" + +from urllib.error import HTTPError +import web +import lxml.html + +def fcc(phenny, input): + """.fcc - Look up a callsign issued by the FCC.""" + + callsign = input.group(2) + + try: + req = web.post("http://www.arrl.org/advanced-call-sign-search", + {'data[Search][terms]': callsign}) + except (HTTPError, IOError): + phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.") + return + + doc = lxml.html.fromstring(req) + result = doc.xpath('//h3') + if len(result) != 2: + phenny.reply('No results found for {0}'.format(callsign)) + return + + response = result[0].text_content().strip() + phenny.say(response) +fcc.rule = (['fcc'], r'(.*)') + +if __name__ == '__main__': + print(__doc__.strip()) +