You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
from inscriptis import get_text
|
|
import os
|
|
import Utils
|
|
|
|
|
|
class Article:
|
|
def __init__(self, articleObj):
|
|
self.text = get_text(articleObj["summary"]["content"])
|
|
self.title = articleObj["title"]
|
|
self.date = Utils.timestampToDate(articleObj["timestampUsec"])
|
|
self.currentPageNumber = 1
|
|
terminal_width, terminal_height = os.get_terminal_size()
|
|
terminal_width -= 76
|
|
terminal_height -= 1
|
|
start_of_chunk = 0
|
|
end_of_chunk = 0
|
|
rows_passed = 0
|
|
self.chunks = []
|
|
i = 0
|
|
column_position = 0
|
|
for s in self.text:
|
|
i += 1
|
|
column_position += 1
|
|
if column_position > terminal_width or s == "\n":
|
|
rows_passed += 1
|
|
column_position = 0
|
|
if rows_passed > terminal_height - 2:
|
|
end_of_chunk = i
|
|
self.chunks.append(self.text[start_of_chunk:end_of_chunk])
|
|
start_of_chunk = end_of_chunk
|
|
rows_passed = 0
|
|
if end_of_chunk <= i:
|
|
self.chunks.append(self.text[start_of_chunk:i])
|
|
self.firstPage = self.chunks[0]
|
|
self.numberOfPages = len(self.chunks)
|
|
|
|
def scrollDown(self):
|
|
if self.currentPageNumber == self.numberOfPages:
|
|
pass
|
|
else:
|
|
self.currentPageNumber += 1
|
|
print(self.currentPageNumber)
|
|
return self.chunks[self.currentPageNumber - 1]
|
|
|
|
def scrollUp(self):
|
|
if self.currentPageNumber == 1:
|
|
pass
|
|
else:
|
|
self.currentPageNumber -= 1
|
|
print(self.currentPageNumber)
|
|
return self.chunks[self.currentPageNumber - 1]
|