From b91de3886ecb38b6621dc35fa18a4c7f10fde780 Mon Sep 17 00:00:00 2001 From: "Sean B. Palmer" Date: Thu, 11 Sep 2008 17:18:44 +0100 Subject: Added oblique.py, a new web services module. --- modules/codepoints.py | 2 ++ modules/etymology.py | 2 +- modules/head.py | 10 +++++++-- modules/oblique.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ modules/search.py | 1 + modules/wikipedia.py | 2 +- web.py | 6 +++++ 7 files changed, 81 insertions(+), 4 deletions(-) create mode 100755 modules/oblique.py 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'^.*?(?'): continue + line = line.strip() + if not line.endswith(''): 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,}?(?