From d927a2a1deb6717d41eb1be15abcb04c0f7a82c0 Mon Sep 17 00:00:00 2001 From: okhin Date: Wed, 30 Mar 2016 17:37:07 +0200 Subject: [PATCH] Fix #23 let's truncate the tweet --- wantzel.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wantzel.py b/wantzel.py index b686113..47abda0 100644 --- a/wantzel.py +++ b/wantzel.py @@ -561,9 +561,17 @@ class Wantzel(object): # lesser than future if today < entry.published_parsed < now: if self.last_entry_published < entry.published_parsed: + # Let's see if we can truncate the lenght of the tweet + # We have 5 chars for the language, so max-length is 135 + title = entry.title.encode("utf-8") + link = entry.link.encode("utf-8") + if len(title) + len(link) > 135: + # What is the number of chars we need to remove + excess = len(title) + len(link) - 135 + title = ''.join([title[:-(excess + 4)], u' ...']) tweet(messages["tweet_rp_%s" % language] % ( - entry.title.encode("utf-8"), - entry.link.encode("utf-8") + title, + link )) Utils.debug(entry.published_parsed) Utils.debug(entry.title) -- GitLab