def get_sync_content(article, client, social_type): # Title title = article.title title_count = sina_client.count_words(title) # Short url url = '%s%s' % (settings.SITE, article.get_absolute_url()) if hasattr(client, 'get_short_url'): short_url = client.get_short_url(url) else: short_url = url short_url_count = sina_client.count_words(short_url) # Base content base = u"发表了文章《》 - ... " base_count = sina_client.count_words(base) rest_count = MAX_WORDS - title_count - short_url_count - base_count rest_content = '' for word in iter(strip_html(article.content)): rest_count -= sina_client.count_words(word) threshold = 0 if not social_type==2 else 3 if rest_count < threshold: break rest_content += word content = u"发表了文章《%s》 - %s... %s" % (title, rest_content, short_url) return content
def count_words(self, content): return weibo_client.count_words(content)