def urlize_twitter(text): """ Replace #hashtag and @username references in a tweet with HTML text. """ html = TwitterText(text).autolink.auto_link() return mark_safe(html.replace( 'twitter.com/search?q=', 'twitter.com/search/realtime/'))
def urlize_twitter(text): """ Replace #hashtag and @username references in a tweet with HTML text. """ html = TwitterText(text).autolink.auto_link() return mark_safe( html.replace('twitter.com/search?q=', 'twitter.com/search/realtime/'))
def twitter_text(text, search_query=False): """ Parses a text string through the TwitterText auto_link method and if search_query is passed, through the hit_highlight method. """ tt = TwitterText(text) if search_query: tt.text = tt.highlighter.hit_highlight(query=search_query) tt.text = tt.autolink.auto_link() return tt.text
def twitter_text(text, search_query = False): """ Parses a text string through the TwitterText auto_link method and if search_query is passed, through the hit_highlight method. """ tt = TwitterText(text) if search_query: tt.text = tt.highlighter.hit_highlight(query = search_query) tt.text = tt.autolink.auto_link() return tt.text
def html_text(self): if self.source == 'twitter': # careful: TwitterText.autolink.auto_link does *not* escape # HTML. On the other hand, the twitter API will give you # the text HTML escaped. Why, please ask the respective # authors. It's dumb ... return Markup(TwitterText(self.text).autolink.auto_link()) return Markup(self.text)
def urlize_twitter(text): """ Replace #hashtag and @username references in a tweet with HTML text. """ tt = TwitterText(text) html = tt.autolink.auto_link() html = html.replace("twitter.com/search?q=", "twitter.com/search/realtime/") return mark_safe(html)
def validate_tweet(message): twitter_text = TwitterText(message) ret = twitter_text.validation.tweet_invalid() if not ret: return True else: if ret == 'Too long': ret = 'Too Long (%d) characters' % len(message) raise TwitterValidationError(ret)
def process_links(msg_list): """ For each message, extract URLs, shorten them, add link meta data """ data = [] for msg in msg_list: message = msg.get('message') tt = TwitterText(message) ex = tt.extractor orig_urls = ex.extract_urls() short_urls = ex.extract_urls(shorten_url) link = short_urls[0] if len(short_urls) > 0 else None for a, b in zip(orig_urls, short_urls): message = message.decode("utf-8").replace(a, b).encode("utf-8") puts(colored.yellow('INFO: Message: %s (%s)' % (message, len(message)))) obj = dict(message=message, meta=dict(link=link)) data.append(obj) return data
def markup_tweet(text): return Markup(TwitterText(text).autolink.auto_link())
print(f"Day {dayname} has no Pixiv tags!") tagnames: Set[str] = set() for tag in day.tags: if tag.name.startswith("#"): print(f"Day {dayname} has improper tag {tag}!") if tag.name in tagnames: print(f"Day {dayname} has duplicate tag {tag}!") tagnames.add(tag.name) if not tag.is_twitter() and not tag.is_pixiv(): print(f"Day {dayname} has tag with no platform!") if tag.is_twitter(): twittertext = TwitterText("#" + tag.name) if not twittertext.validation.valid_hashtag(): print(f"Day {dayname} has invalid twitter tag {tag}!") tagcount += 1 if len(day.citations) == 0: print(f"Day {dayname} has no citations!") if LINK_REGEX.search(day.explanation): print(f"Day {dayname} has links in explanation!") tweettext = format_twitter(day) invalid = TwitterText(tweettext).validation.tweet_invalid() if invalid: print(
def render_html(self): if self.feed.type == 'TW': tt = TwitterText(self.text) return tt.autolink.auto_link() else: return self.text