From b4444c58c97d5c32fedafc1566b8a0e94bef59e7 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Fri, 17 Apr 2015 09:16:08 -0500 Subject: [PATCH] twitter stupidly "shortens" find.com into http://t.co/u44JiITiuc, cope try to pluck out simple urls in basic tlds and treat their length as a t.co url if it's longer than the url being shortened of course this will not catch all urls, but i'm not going to load a whole suffix list or library just to deal with this stupid shit --- script/post_to_twitter | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/script/post_to_twitter b/script/post_to_twitter index ad82d8b..35b3fd1 100755 --- a/script/post_to_twitter +++ b/script/post_to_twitter @@ -44,6 +44,11 @@ Time.now - 1.days).order(:id).each_with_index do |s,x| title = "- #{title}" end + # if there are any urls in the title, they should be sized (at least) to a + # twitter t.co url + left_len -= (title.scan(/[^ ]\.(com|org|net|edu)/i).map{|u| [ 0, + Twitter::TCO_LEN ].max }.inject(:+)).to_i + if title.bytesize > left_len status = title[0, left_len - 3] + "..." + status else