Skip to content

Instantly share code, notes, and snippets.

@voidfiles
Created February 15, 2011 07:09
Show Gist options
  • Select an option

  • Save voidfiles/827210 to your computer and use it in GitHub Desktop.

Select an option

Save voidfiles/827210 to your computer and use it in GitHub Desktop.
Joins a piece of text with a url to form max length tweet
long_tweet = 'asdfasdf asd fasd fasdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdfasdf asdfasdfas dfasd fasd fasdf asdf asdf asdf asdf asdf asdf '
short_tweet = 'asdfasdf asd fasd fasdf asdf asdf asdf asdf asdf asdf asdf asdf'
url = "http://sia.tw/4fgs4"
def join_url(tweet, url):
max_tweet_length = 139
if url:
max_tweet_length = max_tweet_length - len(url)
if len(tweet) > max_tweet_length:
tweet = tweet[0:max_tweet_length - 4].strip() + "... " + url
else:
tweet = tweet + " " + url
return tweet
joined = join_url(long_tweet, url)
print joined
print len(joined)
joined = join_url(short_tweet, url)
print joined
print len(joined)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment