Skip to content

Instantly share code, notes, and snippets.

Last active Sep 4, 2017
What would you like to do?
Easy tweetstorms for pythonista on ios. Usage: have a twitter account on device, run the script, approve access, type your text into the box.
# like the previous version ( but threading by reply previous tweet instead of first one
from dialogs import text_dialog
import twitter
from time import sleep
acct = twitter.get_all_accounts()[0]
# if there are multiple accounts this will need to be changed to get different account. I only have one account so don't care.
# right now I also don't care to have authentication error handling, will need to experiment with unauthenticated devices to figure out what it throws.
def numerate_tweets(tweetlist):
numtweets = len(tweetlist)
newoutlist = []
for index, tweet in enumerate(tweetlist):
numerizer = " (%d/%d)" % (index + 1, numtweets)
newoutlist.append(tweet.strip() + numerizer)
return newoutlist
def make_tweetstorm_list():
text = text_dialog()
if text: # bail on cancel
if len(text) > 140:
words = text.split(" ")
outlist = []
thistweet = ""
# will reserve ten characters for numbers, should handle reasonable-length tweetstorms.
for w in words:
if len(thistweet + " " + w) > 130:
thistweet = w.strip()
thistweet = thistweet + " " + w.strip()
tweetlist = numerate_tweets(outlist)
tweetlist = [text]
return tweetlist
print("tweetstorm cancelled!")
return None
def post_tweet_list_as_replies(tweetlist):
if tweetlist:
firstpost = twitter.post_tweet(acct, tweetlist[0])
if len(tweetlist) > 1:
params = {"in_reply_to_status_id": firstpost["id_str"]}
newlist = tweetlist[1:]
for tweet in newlist:
sleep(1) # to avoid pissing off the twitter api gods. might still run into rate-limit issues for really big tweetstorms
new_post = twitter.post_tweet(acct, tweet, params)
params = {"in_reply_to_status_id": new_post["id_str"]}
return firstpost # so it can be printed or saved or url-extracted or something in bigger scripts.
print("you didn't give me any tweets to post, sorry.")
return None
def tweetstorm():
tweetlist = make_tweetstorm_list()
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment