start using callook.info instead of scraping from ARRL

master
mutantmonkey 2011-11-30 13:44:12 -05:00
parent 5e3f24fadb
commit 01bcae7a03
1 changed files with 6 additions and 7 deletions

View File

@ -6,7 +6,7 @@ author: mutantmonkey <mutantmonkey@mutantmonkey.in>
from urllib.error import HTTPError from urllib.error import HTTPError
import web import web
import lxml.html 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."""
@ -14,19 +14,18 @@ def fcc(phenny, input):
callsign = input.group(2) callsign = input.group(2)
try: try:
req = web.post("http://www.arrl.org/advanced-call-sign-search", req = web.get("http://callook.info/{0}/json".format(web.quote(callsign)))
{'data[Search][terms]': callsign})
except (HTTPError, IOError): except (HTTPError, IOError):
phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.") phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.")
return return
doc = lxml.html.fromstring(req) data = json.loads(req)
result = doc.xpath('//h3') if len(data) <= 0:
if len(result) != 2:
phenny.reply('No results found for {0}'.format(callsign)) phenny.reply('No results found for {0}'.format(callsign))
return return
response = result[0].text_content().strip() response = "{0} - {1} - {2}".format(data['current']['callsign'],
data['name'], data['otherInfo']['ulsUrl'])
phenny.say(response) phenny.say(response)
fcc.rule = (['fcc'], r'(.*)') fcc.rule = (['fcc'], r'(.*)')