From d01c6581dc798d8000ad5c1ce3c43328975dc2be Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 19 Mar 2015 01:57:48 +0100 Subject: [PATCH] Allow Transbot to handle multi-sentence tweets. --- transbot.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/transbot.py b/transbot.py index 7bdea23..de3fea8 100644 --- a/transbot.py +++ b/transbot.py @@ -54,8 +54,21 @@ for status in timeline: auth = tweepy.OAuthHandler(a[1], a[2]) auth.set_access_token(a[3], a[4]) api = tweepy.API(auth) + + tstring = "" + curstr = "" + + for word in text.split(" "): + curstr += word + if word[-1] in "!?.": + tstring += translate.Translator(to_lang=a[0]).translate(curstr)) + " " + curstr = "" + + if curstr != "": + tstring += translate.Translator(to_lang=a[0]).translate(curstr)) + try: - api.update_status(translate.Translator(to_lang=a[0]).translate(text).encode('utf-8')[:140]) + api.update_status(tstring.encode('utf-8')[:140]) tw_counter += 1 except tweepy.error.TweepError, e: print e