diff --git a/ttp.py b/ttp.py index 27102a9..aedb61d 100644 --- a/ttp.py +++ b/ttp.py @@ -96,13 +96,14 @@ class ParseResult(object): ''' - def __init__(self, urls, users, reply, lists, tags, html): + def __init__(self, urls, users, reply, lists, tags, html, text): self.urls = list(set(urls)) if urls else [] #fixes dups self.users = list(set(users)) if users else [] self.lists = list(set(lists)) if lists else [] self.reply = list(set(reply)) if reply else [] self.tags = list(set(tags)) if tags else [] self.html = html + self.text = text class Parser(object): @@ -122,16 +123,18 @@ def parse(self, text, html=True): reply = reply.groups(0)[0] if reply is not None else None parsed_html = self._html(text) if html else self._text(text) + parsed_text = self._text(text) return ParseResult(self._urls, self._users, reply, - self._lists, self._tags, parsed_html) + self._lists, self._tags, parsed_html, + parsed_text) def _text(self, text): '''Parse a Tweet without generating HTML.''' - URL_REGEX.sub(self._parse_urls, text) - USERNAME_REGEX.sub(self._parse_users, text) - LIST_REGEX.sub(self._parse_lists, text) - HASHTAG_REGEX.sub(self._parse_tags, text) - return None + text = URL_REGEX.sub(self._parse_urls, text) + text = USERNAME_REGEX.sub('', text) + text = LIST_REGEX.sub(self._parse_lists, text) + text = HASHTAG_REGEX.sub(self._parse_tags, text) + return text def _html(self, text): '''Parse a Tweet and generate HTML.'''