Updated the translate module, the web interface having changed.
parent
986953131d
commit
d7f8faabe8
3
irc.py
3
irc.py
|
@ -43,9 +43,12 @@ class Bot(asynchat.async_chat):
|
||||||
|
|
||||||
def __write(self, args, text=None):
|
def __write(self, args, text=None):
|
||||||
# print '%r %r %r' % (self, args, text)
|
# print '%r %r %r' % (self, args, text)
|
||||||
|
try:
|
||||||
if text is not None:
|
if text is not None:
|
||||||
self.push(' '.join(args) + ' :' + text + '\r\n')
|
self.push(' '.join(args) + ' :' + text + '\r\n')
|
||||||
else: self.push(' '.join(args) + '\r\n')
|
else: self.push(' '.join(args) + '\r\n')
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
def write(self, args, text=None):
|
def write(self, args, text=None):
|
||||||
# This is a safe version of __write
|
# This is a safe version of __write
|
||||||
|
|
|
@ -109,7 +109,7 @@ def dict(phenny, input):
|
||||||
result = input.group(2).encode('utf-8') + ' - '
|
result = input.group(2).encode('utf-8') + ' - '
|
||||||
for key in sorted(results.keys()):
|
for key in sorted(results.keys()):
|
||||||
if results[key]:
|
if results[key]:
|
||||||
result += key + ' 1. ' + results[key][0]
|
result += (key or '') + ' 1. ' + results[key][0]
|
||||||
if len(results[key]) > 1:
|
if len(results[key]) > 1:
|
||||||
result += ', 2. ' + results[key][1]
|
result += ', 2. ' + results[key][1]
|
||||||
result += '; '
|
result += '; '
|
||||||
|
|
|
@ -11,7 +11,7 @@ http://inamidst.com/phenny/
|
||||||
import re, time
|
import re, time
|
||||||
import web
|
import web
|
||||||
|
|
||||||
r_translation = re.compile(r'<div style=padding:10px;>([^<]+)</div>')
|
r_translation = re.compile(r'<div style="padding:\S+?;">([^<]+)</div>')
|
||||||
|
|
||||||
def guess_language(phrase):
|
def guess_language(phrase):
|
||||||
languages = {
|
languages = {
|
||||||
|
@ -40,15 +40,17 @@ def guess_language(phrase):
|
||||||
if '_' in lang:
|
if '_' in lang:
|
||||||
j = lang.find('_')
|
j = lang.find('_')
|
||||||
lang = lang[:j]
|
lang = lang[:j]
|
||||||
try: return languages[lang]
|
try: return languages[lang].lower()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return lang
|
return lang.lower()
|
||||||
return 'Moon Language'
|
return 'Moon Language'
|
||||||
|
|
||||||
def translate(phrase, lang, target='en'):
|
def translate(phrase, lang, target='en'):
|
||||||
babelfish = 'http://world.altavista.com/tr'
|
babelfish = 'http://uk.babelfish.yahoo.com/translate_txt'
|
||||||
form = {
|
form = {
|
||||||
|
'ei': 'UTF-8',
|
||||||
'doit': 'done',
|
'doit': 'done',
|
||||||
|
'fr': 'bf-home',
|
||||||
'intl': '1',
|
'intl': '1',
|
||||||
'tt': 'urltext',
|
'tt': 'urltext',
|
||||||
'trtext': phrase,
|
'trtext': phrase,
|
||||||
|
@ -89,7 +91,7 @@ def tr(phenny, input):
|
||||||
else: return phenny.reply('"%s" (%s -> %s)' % \
|
else: return phenny.reply('"%s" (%s -> %s)' % \
|
||||||
(translation, input, output))
|
(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())
|
return phenny.reply(error % input.title())
|
||||||
|
|
||||||
# Otherwise, it's English, so mangle it for fun
|
# Otherwise, it's English, so mangle it for fun
|
||||||
|
|
Loading…
Reference in New Issue