Created
February 15, 2011 07:09
-
-
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
This file contains hidden or 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
| 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