Allow Transbot to handle multi-sentence tweets.
This commit is contained in:
parent
9afd088394
commit
d01c6581dc
1 changed files with 14 additions and 1 deletions
15
transbot.py
15
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
|
||||
|
|
Loading…
Reference in a new issue