Fixed bugs in zipinfo and netcraft

This commit is contained in:
James Vega 2004-04-30 01:39:29 +00:00
parent b5ad1bed54
commit 65ad15dd45
2 changed files with 16 additions and 18 deletions

View File

@ -250,7 +250,7 @@ class Http(callbacks.Privmsg):
s = ', or '.join(defs) s = ', or '.join(defs)
irc.reply('%s could be %s' % (acronym, s)) irc.reply('%s could be %s' % (acronym, s))
_netcraftre = re.compile(r'whatos text -->(.*?)<a href="/up/acc', re.S) _netcraftre = re.compile(r'td align="left">\s+<a[^>]+>(.*?)<a href', re.S)
def netcraft(self, irc, msg, args): def netcraft(self, irc, msg, args):
"""<hostname|ip> """<hostname|ip>
@ -263,8 +263,9 @@ class Http(callbacks.Privmsg):
m = self._netcraftre.search(html) m = self._netcraftre.search(html)
if m: if m:
html = m.group(1) html = m.group(1)
s = utils.htmlToText(html, tagReplace='').strip('\xa0 ') s = utils.htmlToText(html, tagReplace='').strip()
irc.reply(s[9:]) # Snip off "the site" s = s.rstrip('-').strip()
irc.reply(s) # Snip off "the site"
elif 'We could not get any results' in html: elif 'We could not get any results' in html:
irc.reply('No results found for %s.' % hostname) irc.reply('No results found for %s.' % hostname)
else: else:
@ -398,21 +399,16 @@ class Http(callbacks.Privmsg):
# Zone, Daylight Time(?), Latitude, Longitude # Zone, Daylight Time(?), Latitude, Longitude
info = utils.htmlToText(rawinfo) info = utils.htmlToText(rawinfo)
info = info.split() info = info.split()
resp = [] zipindex = info.index(zipcode)
# County was more than one word. Hopfully it was only two words resp = ['City: %s' % ' '.join(info[:zipindex-1]),
if (len(info[-9]) > 2): 'State: %s' % info[zipindex-1],
resp.append('City: %s' % ' '.join(info[:-10])) 'County: %s' % ' '.join(info[zipindex+1:-6]),
resp.append('State: %s' % info[-10]) 'Area Code: %s' % info[-5],
resp.append('County: %s' % ' '.join(info [-6:-8])) 'Time Zone: %s' % info[-4],
else: 'Daylight Savings: %s' % info[-3],
resp.append('City: %s' % ' '.join(info[:-9])) 'Latitude: %s (%s)' % (info[-2], latdir),
resp.append('State: %s' % info[-9]) 'Longitude: %s (%s)' % (info[-1], longdir),
resp.append('County: %s' % info[-7]) ]
resp.append('Area Code: %s' % info[-5])
resp.append('Time Zone: %s' % info[-4])
resp.append('Daylight Savings: %s' % info[-3])
resp.append('Latitude: %s (%s)' % (info[-2], latdir))
resp.append('Longitude: %s (%s)' % (info[-1], longdir))
irc.reply('; '.join(resp)) irc.reply('; '.join(resp))

View File

@ -117,6 +117,8 @@ if network:
self.assertRegexp('zipinfo 00000', self.assertRegexp('zipinfo 00000',
r'Only about \d+,\d+ of the \d+,\d+ possible') r'Only about \d+,\d+ of the \d+,\d+ possible')
self.assertRegexp('zipinfo 78014', 'County: La Salle') self.assertRegexp('zipinfo 78014', 'County: La Salle')
self.assertRegexp('zipinfo 90001',
r'City: Los Angeles.*County: Los Angeles')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: