Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit d4f3dcd

Browse files
committed
Adds support for 280 character limit
1 parent fd10c45 commit d4f3dcd

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

tests/test_tweet_length.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,12 @@ def test_split_tweets(self):
6363
tweets = self.api._TweetTextWrap(test_tweet)
6464
self.assertEqual(
6565
tweets[0],
66-
"Anatole went out of the room and returned a few minutes later wearing a fur coat girt with a silver belt, and a sable cap jauntily set on")
66+
"Anatole went out of the room and returned a few minutes later wearing a fur coat girt with a silver belt, and a sable cap jauntily set on one side and very becoming to his handsome face. Having looked in a mirror, and standing before Dolokhov in the same pose he had assumed")
6767
self.assertEqual(
6868
tweets[1],
69-
"one side and very becoming to his handsome face. Having looked in a mirror, and standing before Dolokhov in the same pose he had assumed")
70-
self.assertEqual(
71-
tweets[2],
7269
"before it, he lifted a glass of wine.")
7370

74-
test_tweet = "t.co went t.co of t.co room t.co returned t.co few minutes later"
71+
test_tweet = "t.co went t.co of t.co room t.co returned t.co few minutes later and then t.co went to t.co restroom and t.co was sad because t.co did not have any t.co toilet paper"
7572
tweets = self.api._TweetTextWrap(test_tweet)
76-
self.assertEqual(tweets[0], 't.co went t.co of t.co room t.co returned')
77-
self.assertEqual(tweets[1], 't.co few minutes later')
73+
self.assertEqual(tweets[0], 't.co went t.co of t.co room t.co returned t.co few minutes later and then t.co went to t.co restroom and t.co was sad because')
74+
self.assertEqual(tweets[1], 't.co did not have any t.co toilet paper')

twitter/api.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
if sys.version_info > (3,):
7373
long = int
7474

75-
CHARACTER_LIMIT = 140
75+
CHARACTER_LIMIT = 280
7676

7777
# A singleton representing a lazily instantiated FileCache.
7878
DEFAULT_CACHE = object()
@@ -976,8 +976,8 @@ def PostUpdate(self,
976976
977977
Args:
978978
status (str):
979-
The message text to be posted. Must be less than or equal to 140
980-
characters.
979+
The message text to be posted. Must be less than or equal to
980+
CHARACTER_LIMIT characters.
981981
media (int, str, fp, optional):
982982
A URL, a local file, or a file-like object (something with a
983983
read() method), or a list of any combination of the above.
@@ -1029,8 +1029,8 @@ def PostUpdate(self,
10291029
otherwise the payload will contain the full user data item.
10301030
verify_status_length (bool, optional):
10311031
If True, api throws a hard error that the status is over
1032-
140 characters. If False, Api will attempt to post the
1033-
status.
1032+
CHARACTER_LIMIT characters. If False, Api will attempt to post
1033+
the status.
10341034
Returns:
10351035
(twitter.Status) A twitter.Status instance representing the
10361036
message posted.
@@ -1042,8 +1042,8 @@ def PostUpdate(self,
10421042
else:
10431043
u_status = str(status, self._input_encoding)
10441044

1045-
if verify_status_length and calc_expected_status_length(u_status) > 140:
1046-
raise TwitterError("Text must be less than or equal to 140 characters.")
1045+
if verify_status_length and calc_expected_status_length(u_status) > CHARACTER_LIMIT:
1046+
raise TwitterError("Text must be less than or equal to CHARACTER_LIMIT characters.")
10471047

10481048
if auto_populate_reply_metadata and not in_reply_to_status_id:
10491049
raise TwitterError("If auto_populate_reply_metadata is True, you must set in_reply_to_status_id")
@@ -1514,7 +1514,7 @@ def PostMultipleMedia(self, status, media, possibly_sensitive=None,
15141514

15151515
def _TweetTextWrap(self,
15161516
status,
1517-
char_lim=140):
1517+
char_lim=CHARACTER_LIMIT):
15181518

15191519
if not self._config:
15201520
self.GetHelpConfiguration()
@@ -1525,7 +1525,7 @@ def _TweetTextWrap(self,
15251525
words = re.split(r'\s', status)
15261526

15271527
if len(words) == 1 and not is_url(words[0]):
1528-
if len(words[0]) > 140:
1528+
if len(words[0]) > CHARACTER_LIMIT:
15291529
raise TwitterError({"message": "Unable to split status into tweetable parts. Word was: {0}/{1}".format(len(words[0]), char_lim)})
15301530
else:
15311531
tweets.append(words[0])
@@ -1541,7 +1541,7 @@ def _TweetTextWrap(self,
15411541
else:
15421542
new_len += len(word) + 1
15431543

1544-
if new_len > 140:
1544+
if new_len > CHARACTER_LIMIT:
15451545
tweets.append(' '.join(line))
15461546
line = [word]
15471547
line_length = new_len - line_length
@@ -1559,12 +1559,12 @@ def PostUpdates(self,
15591559
"""Post one or more twitter status messages from the authenticated user.
15601560
15611561
Unlike api.PostUpdate, this method will post multiple status updates
1562-
if the message is longer than 140 characters.
1562+
if the message is longer than CHARACTER_LIMIT characters.
15631563
15641564
Args:
15651565
status:
15661566
The message text to be posted.
1567-
May be longer than 140 characters.
1567+
May be longer than CHARACTER_LIMIT characters.
15681568
continuation:
15691569
The character string, if any, to be appended to all but the
15701570
last message. Note that Twitter strips trailing '...' strings
@@ -2978,7 +2978,7 @@ def GetDirectMessages(self,
29782978
objects. [Optional]
29792979
full_text:
29802980
When set to True full message will be included in the returned message
2981-
object if message length is bigger than 140 characters. [Optional]
2981+
object if message length is bigger than CHARACTER_LIMIT characters. [Optional]
29822982
page:
29832983
If you want more than 200 messages, you can use this and get 20 messages
29842984
each time. You must recall it and increment the page value until it

0 commit comments

Comments
 (0)