Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. def mk_tweet(self, prefix, twitter_ids, video_name, authors, video_url):
  2. """
  3. Should return (examples):
  4. #lca2017 My Talk Title - @CarlFK http://youtu.be/123456
  5. #lca2017 My Talk Title - Carl Karsten http://youtu.be/123456
  6. #lca2017 My Really Long Talk Title That Got Shortened Because It Is Lon... - Carl Karsten http://youtu.be/123456
  7. """
  8.  
  9. TWITTER_LENGTH_MAX = 140
  10.  
  11. # always shorten video_url's (if not already shortened)
  12. if len(video_url) > 25:
  13. video_url = self.shorten(video_url)
  14.  
  15. AVAILABLE_CHARS = TWITTER_LENGTH_MAX - len(prefix) - len(video_url) - 5
  16.  
  17. message = '#{prefix} {video_name} - {authors} {video_url}'.format(
  18. prefix=prefix,
  19. video_url=video_url
  20. )
  21.  
  22. if twitter_ids:
  23. authors = twitter_ids
  24. else:
  25. authors = authors
  26.  
  27. if AVAILABLE_CHARS - len(video_name) - len(authors) >= 0:
  28. return message.format(video_name=video_name, authors=authors)
  29. else:
  30. MAX_TITLE_CHARS = AVAILABLE_CHARS - len(authors)
  31. shortened_video_name = video_name[:AVAILABLE_CHARS]
  32. return message.format(video_name=shortened_video_name, authors=authors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement