|
|
|
@ -6,14 +6,15 @@ from RedditCommentsParser import RedditComments
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Render:
|
|
|
|
class Render:
|
|
|
|
def __init__(self, id, content, url, links):
|
|
|
|
def __init__(self, title, content, url, links):
|
|
|
|
if Utils.checkReddit(self.url):
|
|
|
|
self.title = title
|
|
|
|
comments_link = Utils.checkRedditComments(links)
|
|
|
|
self.links = links
|
|
|
|
if comments_link:
|
|
|
|
self.content = content
|
|
|
|
commentsObj = RedditComments(comments_link)
|
|
|
|
self.splitByPages()
|
|
|
|
commentsObj.getComments()
|
|
|
|
self.url = url
|
|
|
|
for comment in commentsObj.comments:
|
|
|
|
self.areCommentsLoaded = False
|
|
|
|
self.text += "\n\n" + comment
|
|
|
|
|
|
|
|
|
|
|
|
def splitByPages(self):
|
|
|
|
self.currentPageNumber = 1
|
|
|
|
self.currentPageNumber = 1
|
|
|
|
terminal_width, terminal_height = os.get_terminal_size()
|
|
|
|
terminal_width, terminal_height = os.get_terminal_size()
|
|
|
|
terminal_width -= 76
|
|
|
|
terminal_width -= 76
|
|
|
|
@ -23,7 +24,7 @@ class Render:
|
|
|
|
self.chunks = []
|
|
|
|
self.chunks = []
|
|
|
|
i = 0
|
|
|
|
i = 0
|
|
|
|
column_position = 0
|
|
|
|
column_position = 0
|
|
|
|
for s in self.text:
|
|
|
|
for s in self.content:
|
|
|
|
i += 1
|
|
|
|
i += 1
|
|
|
|
column_position += 1
|
|
|
|
column_position += 1
|
|
|
|
if column_position > terminal_width or s == "\n":
|
|
|
|
if column_position > terminal_width or s == "\n":
|
|
|
|
@ -31,14 +32,26 @@ class Render:
|
|
|
|
column_position = 0
|
|
|
|
column_position = 0
|
|
|
|
if rows_passed > terminal_height - 2:
|
|
|
|
if rows_passed > terminal_height - 2:
|
|
|
|
end_of_chunk = i
|
|
|
|
end_of_chunk = i
|
|
|
|
self.chunks.append(self.text[start_of_chunk:end_of_chunk])
|
|
|
|
self.chunks.append(self.content[start_of_chunk:end_of_chunk])
|
|
|
|
start_of_chunk = end_of_chunk
|
|
|
|
start_of_chunk = end_of_chunk
|
|
|
|
rows_passed = 0
|
|
|
|
rows_passed = 0
|
|
|
|
if end_of_chunk <= i:
|
|
|
|
if end_of_chunk <= i:
|
|
|
|
self.chunks.append(self.text[start_of_chunk:i])
|
|
|
|
self.chunks.append(self.content[start_of_chunk:i])
|
|
|
|
self.firstPage = self.chunks[0]
|
|
|
|
self.firstPage = self.chunks[0]
|
|
|
|
self.numberOfPages = len(self.chunks)
|
|
|
|
self.numberOfPages = len(self.chunks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def loadComments(self):
|
|
|
|
|
|
|
|
if self.areCommentsLoaded is False:
|
|
|
|
|
|
|
|
self.areCommentsLoaded = True
|
|
|
|
|
|
|
|
if Utils.checkReddit(self.url):
|
|
|
|
|
|
|
|
comments_link = Utils.checkRedditComments(self.links)
|
|
|
|
|
|
|
|
if comments_link:
|
|
|
|
|
|
|
|
commentsObj = RedditComments(comments_link)
|
|
|
|
|
|
|
|
commentsObj.getComments()
|
|
|
|
|
|
|
|
for comment in commentsObj.comments:
|
|
|
|
|
|
|
|
self.content += "\n\n" + comment
|
|
|
|
|
|
|
|
self.splitByPages()
|
|
|
|
|
|
|
|
|
|
|
|
def scrollDown(self):
|
|
|
|
def scrollDown(self):
|
|
|
|
if self.currentPageNumber == self.numberOfPages:
|
|
|
|
if self.currentPageNumber == self.numberOfPages:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|