txtv

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

commit b24060e3994d936944b474eda89480f0c0828e40
parent 06a42bfe62b7bf6100e285984ba0465b31ddf85a
Author: Isak Lindhé <isak.e.lindhe@gmail.com>
Date:   Thu, 20 Dec 2018 21:43:22 +0100

yellow color segments

Diffstat:
Mtxtv.py | 15++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/txtv.py b/txtv.py @@ -1,13 +1,22 @@ import bs4 import requests as rq +import colorama +from colorama import Fore, Back, Style from sys import argv if __name__ == '__main__': + colorama.init() page = int(argv[1]) res = rq.get(f'https://www.svt.se/svttext/web/pages/{page}.html') soup = bs4.BeautifulSoup(res.content, 'html.parser') root = soup.find('pre', class_='root') - rows = [ s.get_text() for s in root.find_all() if s.get_text() != ' ' ] - for r in rows: - print(r) + rows = root.find_all('span') + for row in rows: + if row.get_text() == ' ' or 'bgB' in row.attrs['class']: + continue + if 'Y' in row.attrs['class']: + print(Fore.YELLOW + row.get_text() + Fore.RESET) + else: + print(row.get_text()) + colorama.deinit()