Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.'''
Expand Down