From d7f8faabe8f92b06adb43106b667c439a1bb5575 Mon Sep 17 00:00:00 2001
From: "Sean B. Palmer"
Date: Thu, 15 May 2008 10:44:48 +0100
Subject: [PATCH] Updated the translate module, the web interface having
changed.
---
irc.py | 9 ++++++---
modules/dict.py | 2 +-
modules/translate.py | 12 +++++++-----
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/irc.py b/irc.py
index 38fe886..e5bfdc3 100755
--- a/irc.py
+++ b/irc.py
@@ -43,9 +43,12 @@ class Bot(asynchat.async_chat):
def __write(self, args, text=None):
# print '%r %r %r' % (self, args, text)
- if text is not None:
- self.push(' '.join(args) + ' :' + text + '\r\n')
- else: self.push(' '.join(args) + '\r\n')
+ try:
+ if text is not None:
+ self.push(' '.join(args) + ' :' + text + '\r\n')
+ else: self.push(' '.join(args) + '\r\n')
+ except IndexError:
+ pass
def write(self, args, text=None):
# This is a safe version of __write
diff --git a/modules/dict.py b/modules/dict.py
index 61fcee9..df9025d 100755
--- a/modules/dict.py
+++ b/modules/dict.py
@@ -109,7 +109,7 @@ def dict(phenny, input):
result = input.group(2).encode('utf-8') + ' - '
for key in sorted(results.keys()):
if results[key]:
- result += key + ' 1. ' + results[key][0]
+ result += (key or '') + ' 1. ' + results[key][0]
if len(results[key]) > 1:
result += ', 2. ' + results[key][1]
result += '; '
diff --git a/modules/translate.py b/modules/translate.py
index 23ce7e9..27bd094 100755
--- a/modules/translate.py
+++ b/modules/translate.py
@@ -11,7 +11,7 @@ http://inamidst.com/phenny/
import re, time
import web
-r_translation = re.compile(r'
([^<]+)
')
+r_translation = re.compile(r'([^<]+)
')
def guess_language(phrase):
languages = {
@@ -40,15 +40,17 @@ def guess_language(phrase):
if '_' in lang:
j = lang.find('_')
lang = lang[:j]
- try: return languages[lang]
+ try: return languages[lang].lower()
except KeyError:
- return lang
+ return lang.lower()
return 'Moon Language'
def translate(phrase, lang, target='en'):
- babelfish = 'http://world.altavista.com/tr'
+ babelfish = 'http://uk.babelfish.yahoo.com/translate_txt'
form = {
+ 'ei': 'UTF-8',
'doit': 'done',
+ 'fr': 'bf-home',
'intl': '1',
'tt': 'urltext',
'trtext': phrase,
@@ -89,7 +91,7 @@ def tr(phenny, input):
else: return phenny.reply('"%s" (%s -> %s)' % \
(translation, input, output))
- error = "I think it's %s, which I can't translate."
+ error = "I think it's %s, but I can't translate it currently."
return phenny.reply(error % input.title())
# Otherwise, it's English, so mangle it for fun