From 3b8dc335a9039f124a638f6b3f575ccb49eb4e47 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Mon, 13 Mar 2017 23:36:04 +0100 Subject: [PATCH] Handle URLs before translation --- transbot.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/transbot.py b/transbot.py index f9e3faa..469c84b 100755 --- a/transbot.py +++ b/transbot.py @@ -45,7 +45,14 @@ for status in timeline: for a in accounts: two = twitools.twObject(ato=a[1], ase=a[2]) - intext = re.sub(r'https?:\/\/[\S]*', '', text) + split = text.split() + intext = "" + + for s in split: + if re.match(r'https?:\/\/[\S]*', s): + out = " ".join([out, httptools.shortURL(s)]) + else: + out = " ".join([out, s]) tstring = translator.translate(intext, target_language=a[0])['translatedText'].replace("@", "@​") try: