mo6
- Support for sub pages - Fix erroneous refresh on load - Less obtrusive loading banner
#15 · closed · 8 comments
- Support for sub pages - Fix erroneous refresh on load - Less obtrusive loading banner
``` diff --git a/src/tt b/src/tt index 4acc712..5314b6b 100755 --- a/src/tt +++ b/src/tt @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # -*- coding: UTF-8 -*- import sys @@ -15,7 +15,7 @@ from json import loads # Teletekst baseURL TELETEKST = 'https://teletekst-data.nos.nl/json/%s' TTRC = os.path.expanduser('~/.ttrc') -REFRESH_INTERVAL = 60 +REFRESH_INTERVAL = 15 # Tested with python2.7 and python3.5 double_width = False @@ -196,8 +196,9 @@ def main(scr): curses.init_pair(i,(i % 8), int(i/8)) p = load(page) + next_sub_page = p['nextSubPage'] - t_refresh = 0 + t_refresh = time.time() while True: @@ -215,8 +216,11 @@ def main(scr): else: ticks_idle = 0 - if time.time() > t_refresh: - page_next = page + if time.time() > t_refresh: + if next_sub_page != "": + page_next = next_sub_page + else: + page_next = page t_refresh = time.time() + REFRESH_INTERVAL if c == curses.KEY_MOUSE: @@ -248,11 +252,13 @@ def main(scr): if page_next and len(page_next) > 0: page = page_next page_next = None - scr.addstr(9, 12, " ") - scr.addstr(10, 12, " Loading ") - scr.addstr(11, 12, " ") + scr.addstr(0, 0, " * ") scr.refresh() p = load(page) + if p['nextSubPage'] != "": + next_sub_page = p['nextSubPage'] + else: + next_sub_page = page[0:3] ```
Thanks, I'll cherrypick from this one: - Cycling subpages is ok; I might get annoyed by them, so maybe I'll make this configurable or put it behind a key later. 15 seconds is fine with me. - I'd rather leave the loading screen as it is - I usually barely even see it flashing by, but when it takes time it is good to get proper feedback. Ideally it should only show if the loading takes longer than a few hundred msecs, but that requires some kind of async http handling and I'm too lazy to add this
Please cherry pick. Thanks!
You'd might consider leaving the refresh interval to 60 seconds when there are no sub pages.
Also: check for the existence of the key 'nextSubPage': it seems not to be present on all page results. For example: page 888
Some pages don't have correct data: https://teletekst-data.nos.nl/json/500
The loading screen might get annoying looking at pages with a lot of rotating information, like '521'. That's why I like the loading indicator at the top left of the screen.
Check https://github.com/zevv/termtekst/commit/3145f612cff0738bbd00000b4df53f4e0b1e6847