Let the python-twitter library handle message splitting

Twitter auto-converts urls to twitter shortened URLs. This can affect
the math for message splitting. The python-twitter library has this
implemented already, including all of the logic necessary ... so just
use it.

The character '\u2026' is the unicode horizontal ellipsis and is used
to indicate that the message is continued.

Change-Id: I5492a2792f5d11dccbe4a3454396262341449eab
This commit is contained in:
Monty Taylor 2017-09-18 19:43:13 -05:00
parent 4316cbfadd
commit d01cfd3994
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
1 changed files with 1 additions and 10 deletions

View File

@ -56,7 +56,6 @@ import simplemediawiki
import datetime import datetime
import re import re
import ssl import ssl
import textwrap
import twitter import twitter
import urllib import urllib
@ -200,15 +199,7 @@ class Tweet(UpdateInterface):
access_token_secret=self.access_token_secret) access_token_secret=self.access_token_secret)
def update(self, msg): def update(self, msg):
# Limit tweets to 120 characters to facilitate retweets self.api.PostUpdates(msg, continuation='\u2026')
tweets = textwrap.wrap(msg, 120)
if len(tweets) == 1:
# Don't prefix statuses that fit
self.api.PostUpdate(tweets[0])
else:
for index in range(0, len(tweets)):
self.api.PostUpdate("{index}/{tweet}".format(
index=index, tweet=tweets[index]))
def alert(self, msg=None): def alert(self, msg=None):
self.update(msg) self.update(msg)