]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/cmdline.py
reversed multiple twitts so they appear rightside up on the timeline
[z_archive/twitter.git] / twitter / cmdline.py
index d60bbdf59b7241c1676d4286c60924471db3878e..64ba38ca896fe7d13334b3b0cc9e5a66e34b458b 100644 (file)
@@ -74,6 +74,7 @@ from getpass import getpass
 import re
 import os.path
 import locale
+import string
 
 try:
     from ConfigParser import SafeConfigParser
@@ -260,7 +261,6 @@ class AnsiSearchFormatter(object):
 
 _term_encoding = None
 def get_term_encoding():
-    import pdb;pdb.set_trace()
     global _term_encoding
     if not _term_encoding:
         lang = os.getenv('LANG', 'unknown.UTF-8').split('.')
@@ -464,7 +464,34 @@ class SetStatusAction(Action):
         statusTxt = (" ".join(options['extra_args'])
                      if options['extra_args']
                      else str(input("message: ")))
-        twitter.statuses.update(status=statusTxt)
+        replies = []
+        ptr = re.compile("@[\w_]+")
+        while statusTxt:
+            s = ptr.match(statusTxt)
+            if s and s.start() == 0:
+                replies.append(statusTxt[s.start():s.end()])
+                statusTxt = statusTxt[s.end()+1:]
+            else:
+                break
+        replies = " ".join(replies)
+        if len(replies) >= 140:
+            # just go back
+            statusTxt = replies
+            replies = ""
+
+        splitted = []
+        while statusTxt:
+            limit = 140 - len(replies)
+            if len(statusTxt) > limit:
+                end = string.rfind(statusTxt, ' ', 0, limit)
+            else:
+                end = limit
+            splitted.append(" ".join((replies,statusTxt[:end])))
+            statusTxt = statusTxt[end:]
+
+        splitted.reverse()
+        for status in splitted:
+            twitter.statuses.update(status=status)
 
 class TwitterShell(Action):