txtv

Swiss text tv in the terminal
git clone https://git.in0rdr.ch/txtv.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

commit a1bcdaa28f2e169334a683c828677f18515c2a04
parent ce82193cabf014d0cda2afaef6b0808df4b0f78a
Author: Isak Lindhé <isak.e.lindhe@gmail.com>
Date:   Fri, 21 Dec 2018 17:30:04 +0100

using native linebreaking nodes

Diffstat:
Mtxtv.py | 24++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/txtv.py b/txtv.py @@ -31,26 +31,22 @@ def get_page(num) -> list: err(f'When i tried to get the page i just got HTTP status code {res.status_code}.') soup = bs4.BeautifulSoup(res.content, 'html.parser') root = soup.find('pre', class_='root') - rows = root.find_all('span') - return rows + return root -def show_page(rows:list): - until_next_break = LINEWIDTH - for row in rows: - # if row.get_text() == ' ' or 'bgB' in row.attrs['class']: - # continue +def show_page(page): + for node in page: + if isinstance(node, str): + print(node, end='') + continue style = '' - if 'DH' in row.attrs['class']: + if 'DH' in node.attrs['class']: style = Fore.YELLOW + Style.BRIGHT - elif 'Y' in row.attrs['class']: + elif 'Y' in node.attrs['class']: style = Style.DIM - elif 'bgB' in row.attrs['class']: + elif 'bgB' in node.attrs['class']: style = Fore.BLUE - until_next_break -= len(row.get_text()) - print(style + row.get_text() + Style.RESET_ALL, end=('\n' if until_next_break <= 0 else '')) - if until_next_break <= 0: - until_next_break = LINEWIDTH + print(style + node.get_text() + Style.RESET_ALL, end='') if __name__ == '__main__': colorama.init()