Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script to split your long tweet into small chunks of 140 characters limit imposed by Twitter
#!/usr/bin/env python3
import os, sys
max_length = 140
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
if __name__ == "__main__":
if len(sys.argv) == 1:
print("Please enter the text to split")
ss = sys.argv[1]
print("Total length of tweet is %d chars." % len(ss))
if len(ss) > 140:
max_length -= 5
ll = list(chunks(ss, max_length))
for i in range(0,len(ll)):
print(ll[i] + "(%s/%d)" % (str(i+1)[0],len(ll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.