Created
September 22, 2017 03:37
-
-
Save prahladyeri/ee9ced3f084114f722a3c08457ac4ad5 to your computer and use it in GitHub Desktop.
Python script to split your long tweet into small chunks of 140 characters limit imposed by Twitter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") | |
else: | |
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))) | |
print("") | |
else: | |
print(ss) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment