improve wolframalpha unescaping

This commit is contained in:
Ryan Hitchman 2010-02-17 16:24:52 -07:00
parent f39b4bf9cf
commit ca8b24518e
1 changed files with 7 additions and 0 deletions

View File

@ -45,6 +45,13 @@ def wolframalpha(inp):
if not pod_texts: if not pod_texts:
return 'no results' return 'no results'
ret = re.sub(r'\\(.)', r'\1', ret)
def unicode_sub(match):
return unichr(int(match.group(1), 16))
ret = re.sub(r'\\:([0-9a-z]{4})', unicode_sub, ret)
if len(ret) > 430: if len(ret) > 430:
ret = ret[:ret.rfind(' ', 0, 430)] ret = ret[:ret.rfind(' ', 0, 430)]
ret = re.sub(r'\W+$', '', ret) + '...' ret = re.sub(r'\W+$', '', ret) + '...'