diff options
-rwxr-xr-x | modules/codepoints.py | 2 | ||||
-rwxr-xr-x | modules/etymology.py | 2 | ||||
-rwxr-xr-x | modules/head.py | 10 | ||||
-rwxr-xr-x | modules/oblique.py | 62 | ||||
-rwxr-xr-x | modules/search.py | 1 | ||||
-rwxr-xr-x | modules/wikipedia.py | 2 | ||||
-rwxr-xr-x | web.py | 6 |
7 files changed, 81 insertions, 4 deletions
diff --git a/modules/codepoints.py b/modules/codepoints.py index 9ae06b5..e2fc39a 100755 --- a/modules/codepoints.py +++ b/modules/codepoints.py @@ -70,6 +70,8 @@ def u(phenny, input): # phenny.msg('#inamidst', '%r' % arg) if not arg: return phenny.reply('You gave me zero length input.') + elif not arg.strip(' '): + return phenny.reply('%s SPACES' % len(arg)) # @@ space if set(arg.upper()) - set( diff --git a/modules/etymology.py b/modules/etymology.py index 9f3c7b2..430e18e 100755 --- a/modules/etymology.py +++ b/modules/etymology.py @@ -22,7 +22,7 @@ abbrs = [ 'cf', 'lit', 'etc', 'Ger', 'Du', 'Skt', 'Rus', 'Eng', 'Amer.Eng', 'Sp', 'Fr', 'N', 'E', 'S', 'W', 'L', 'Gen', 'J.C', 'dial', 'Gk', '19c', '18c', '17c', '16c', 'St', 'Capt', 'obs', 'Jan', 'Feb', 'Mar', - 'Apr', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' + 'Apr', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'c' ] t_sentence = r'^.*?(?<!%s)(?:\.(?= [A-Z0-9]|\Z)|\Z)' r_sentence = re.compile(t_sentence % ')(?<!'.join(abbrs)) diff --git a/modules/head.py b/modules/head.py index 4cb19e3..8158958 100755 --- a/modules/head.py +++ b/modules/head.py @@ -7,7 +7,7 @@ Licensed under the Eiffel Forum License 2. http://inamidst.com/phenny/ """ -import re, urllib, urlparse, time +import re, urllib, httplib, urlparse, time from htmlentitydefs import name2codepoint import web from tools import deprecated @@ -24,11 +24,17 @@ def head(phenny, input): try: uri = phenny.last_seen_uri[input.sender] except KeyError: return phenny.say('?') + if not uri.startswith('htt'): + uri = 'http://' + uri + try: info = web.head(uri) except IOError: return phenny.say("Can't connect to %s" % uri) + except httplib.InvalidURL: return phenny.say("Not a valid URI, sorry.") if not isinstance(info, list): - info = dict(info) + try: info = dict(info) + except TypeError: + return phenny.reply('Try .head http://example.org/ [optional header]') info['Status'] = '200' else: newInfo = dict(info[0]) diff --git a/modules/oblique.py b/modules/oblique.py new file mode 100755 index 0000000..55a27fc --- /dev/null +++ b/modules/oblique.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +""" +oblique.py - Web Services Interface +Copyright 2008, Sean B. Palmer, inamidst.com +Licensed under the Eiffel Forum License 2. + +http://inamidst.com/phenny/ +""" + +import urllib +import web + +def mappings(uri): + result = {} + bytes = web.get(uri) + for line in bytes.splitlines(): + if not line.startswith('<li>'): continue + line = line.strip() + if not line.endswith('</li>'): continue + + command, template = line[4:-5].split(' ', 1) + if not template.startswith('http://'): continue + result[command] = template + return result + +def o(phenny, input): + """Call a webservice.""" + text = input.group(2) + + if (not o.services) or (text == 'refresh'): + if hasattr(phenny.config, 'services'): + services = phenny.config.services + else: services = 'http://swhack.jottit.com/services' + + o.services = mappings(services) + if text == 'refresh': + return phenny.reply('Okay, found %s services.' % len(o.services)) + + if ' ' in text: + command, args = text.split(' ', 1) + else: command, args = text, '' + command = command.lower() + args = urllib.quote(args) + + if o.services.has_key(command): + template = o.services[command] + template = template.replace('${args}', args) + template = template.replace('${nick}', input.nick) + uri = template.replace('${sender}', input.sender) + + bytes = web.get(uri) + lines = bytes.splitlines() + if lines: + phenny.say(lines[0]) + else: phenny.reply('Sorry, the service is broken.') + else: phenny.reply('Sorry, no such service. See %s' % services) +o.commands = ['o'] +o.example = '.o servicename arg1 arg2 arg3' +o.services = {} + +if __name__ == '__main__': + print __doc__.strip() diff --git a/modules/search.py b/modules/search.py index 1c8dad6..b1123b8 100755 --- a/modules/search.py +++ b/modules/search.py @@ -66,6 +66,7 @@ g.example = '.g swhack' def gc(phenny, input): """Returns the number of Google results for the specified input.""" + if input.nick == 'goatov': return query = input.group(2) if not query: return phenny.reply('.gc what?') diff --git a/modules/wikipedia.py b/modules/wikipedia.py index 9827cc6..6d9bb11 100755 --- a/modules/wikipedia.py +++ b/modules/wikipedia.py @@ -24,7 +24,7 @@ r_redirect = re.compile( abbrs = ['etc', 'ca', 'cf', 'Co', 'Ltd', 'Inc', 'Mt', 'Mr', 'Mrs', 'Dr', 'Ms', 'Rev', 'Fr', 'St', 'Sgt', 'pron', 'approx', 'lit', - 'syn', 'transl'] \ + 'syn', 'transl', 'sess', 'fl'] \ + list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') \ + list('abcdefghijklmnopqrstuvwxyz') t_sentence = r'^.{5,}?(?<!\b%s)(?:\.(?= [A-Z0-9]|\Z)|\Z)' @@ -16,18 +16,24 @@ class Grab(urllib.URLopener): urllib._urlopener = Grab() def get(uri): + if not uri.startswith('http'): + return u = urllib.urlopen(uri) bytes = u.read() u.close() return bytes def head(uri): + if not uri.startswith('http'): + return u = urllib.urlopen(uri) info = u.info() u.close() return info def post(uri, query): + if not uri.startswith('http'): + return data = urllib.urlencode(query) u = urllib.urlopen(uri, data) bytes = u.read() |