def newsfooter(page, category): newsconf = _config['pages']['news'] nextpage = ttxutils.nextpage(page.page) lastpage = ttxutils.nextpage(newsconf['main']['last']) lastregpage = ttxutils.nextpage(newsconf['regional']['last']) if nextpage in [lastpage, lastregpage]: fastext = (red() + 'In Depth ' + green() + 'News Indx' + yellow() + 'Headlines' + cyan() + 'Main Menu') else: fastext = (red() + 'Next News' + green() + 'News Indx' + yellow() + 'Headlines' + cyan() + 'Main Menu') if category: lines = [ '€T€]€GREGIONAL €CHeadlines€G160€CSport €G390', '€D€]€GNATIONAL€C Main menu€G100€CWeather€G 400', fastext ] else: lines = [ '€D€]€CHome news digest€G141€CWorld digest€G142', '€D€]€CNews Index€G102€CFlash€G150€CRegional€G160', fastext ] line = 22 for l in lines: page.addline(line, ttxutils.decode(l)) line += 1 if nextpage > newsconf['regional']['headlines']: page.addfasttext(nextpage, newsconf['regional']['headlines'], newsconf['main']['headlines'], 0x100, 0x8ff, 0x199) else: page.addfasttext(nextpage, newsconf['main']['index'], newsconf['main']['headlines'], 0x100, 0x8ff, 0x199)
def newsheadlinesfooter(page, category): if category: lines = [ '€T€]€GREGIONAL €CHeadlines€G160€CSport €G390', '€D€]€GNATIONAL€C Main menu€G100€CWeather€G 400', red() + 'Next Page' + green() + 'Top Story' + yellow() + 'Reg Sport' + cyan() + 'Main Menu' ] else: lines = [ '€W€]€DGet BBC News on your mobile phone 153', '€D€]€CCATCH UP WITH REGIONAL NEWS €G160', red() + 'News Index' + green() + 'Top Story' + yellow() + 'TV/Radio' + cyan() + 'Main Menu' ] line = 22 for l in lines: page.addline(line, ttxutils.decode(l)) line += 1 if category: page.addfasttext(0x161, 0x161, 0x390, 0x100, 0x8ff, 0x199) else: page.addfasttext(0x102, 0x104, 0x600, 0x100, 0x8ff, 0x199)
def news_page(category : str, pages : dict, number : int, contents : dict, header : List[str], footer : List[str], fasttext : Optional[List[int]] = None): url = contents['link'] page = ttxpage.TeletextPage( f"{category} Page {number:03x} {url}", number) page.header(number) line = 1 for l in header: page.addline(line, decode(l)) line += 1 title = contents['title'] line += page.wrapline(line, 21, page.fixup(title), ttxcolour.green()) colour = ' ' for para in contents['text']: if line <= 21: added = page.wrapline(line, 22, page.fixup(para), colour) if added: line += added + 1 colour = ttxcolour.cyan() line = 25 - len(footer) for l in footer: page.addline(line, decode(l)) line += 1 if fasttext and len(fasttext) in [3, 4, 6]: if len(fasttext) == 3: f = [nextpage(number), *fasttext, 0x8ff, 0x199] if len(fasttext) == 4: f = [*fasttext, 0x8ff, 0x199] else: f = fasttext page.addfasttext(*f) else: page.addfasttext(pages['first'], 0x100, 0x101, 0x100, 0x8ff, 0x199) page.save()
def sport_page(number, contents, add_to_newsreel=False): url = contents['link'] page = ttxpage.TeletextPage("Sport Page {:03x} {}".format(number, url), number) page.header(number) sport_header(page, contents['section']) line = 4 title = contents['title'].replace(" - BBC Sport", "") line += page.wrapline(line, 21, page.fixup(title), ttxcolour.green()) colour = ' ' for para in contents['text']: if line <= 21: added = page.wrapline(line, 22, page.fixup(para), colour) if added: line += added + 1 colour = ttxcolour.cyan() sport_footer(page, contents['section']) page.save(add_to_newsreel=add_to_newsreel)
def cricket_fixture_page(pagenum, dates, cache): nextpage = ttxutils.nextpage(pagenum) page = ttxpage.TeletextPage("Cricket Fixtures", pagenum) maxrows = 18 pages = [] links = [] for offset in dates: date = datetime.date.today() + datetime.timedelta(days=offset) if offset == 0: dayname = "Today" elif offset == -1: dayname = "Yesterday" else: dayname = date.strftime("%A") isodate = date.isoformat() url = f"{_config['cricket_fixtures_url']}/{isodate}" fixes = cricket_fixtures_table(url, cache) header = f"{ttxcolour.yellow()}{dayname}'s Matches" p = [header] for f in fixes: rows = [] r = f"{ttxcolour.white()}{page.fixup(f['series']).upper()}" rows.append(f"{r:<38}") for m in f['matches']: if len(rows)>1: rows.append('') home_team = page.fixup(m['home_team']) away_team = page.fixup(m['away_team']) if m['home_batting']: home_team = f"{home_team:<.16}{ttxcolour.yellow()}*" r = f"{ttxcolour.cyan()}{home_team:<18.18}" else: r = f"{ttxcolour.cyan()}{home_team:<17.17}" r += f"{ttxcolour.white()}v" if m['away_batting']: away_team = f"{away_team:<.16}{ttxcolour.yellow()}*" r += f"{ttxcolour.cyan()}{away_team:<18.18}" else: r += f"{ttxcolour.cyan()}{away_team:<17.17}" rows.append(r) if m['title']: rows.append(f"{ttxcolour.green()}{page.fixup(m['title'])}") if m['home_score'] or m['away_score']: if offset in [-1, 0]: links.append(m['link']) for innings in range(2): if m['home_score'] and innings < len(m['home_score']): a = page.fixup(m['home_score'][innings]) else: a = '' if m['away_score'] and innings < len(m['away_score']): b = page.fixup(m['away_score'][innings]) else: b = '' if a or b: r = f"{ttxcolour.cyan()}{a:<17.17} {b:<17.17}" rows.append(r) r = '' if m['time']: if m['time'] not in ['LIVE', 'V']: r += page.fixup(m['time']) if m['status']: status = page.fixup(m['status']) r += f"¬\t{status}" if m['venue']: venue = m['venue'].replace('Venue: ','').strip() venue = page.fixup(venue) r += f"¬\t{venue}" colour = ttxcolour.green() for ll in textwrap.wrap(r, 39, expand_tabs=False, replace_whitespace=False): if '\t' in ll or '¬' in ll: ll = ll.replace('¬', '\t') ll = ll.replace('\t\t', '\t') if ll.startswith('\t'): ll = ll.replace('\t','') colour = ttxcolour.magenta() else: ll = ll.replace('\t', ttxcolour.magenta()) rows.append(f"{colour}{ll}") colour = ttxcolour.magenta() else: rows.append(f"{colour}{ll}") if ((len(p) + len(rows) < maxrows) or (len(p) == 0 and len(rows) == maxrows)): if len(p)>1: p.append('') p.extend(rows) else: pages.append(p) p = [header] p.extend(rows) if len(fixes) == 0: p.append('') p.append(f'{ttxcolour.cyan()}No matches today.') pages.append(p) subpage = 0 for p in pages: if len(pages) > 1: subpage += 1 page.header(pagenum, subpage, status=0xc000) else: page.header(pagenum, subpage, status=0x8000) sport_header(page, 'Cricket') if len(pages) > 1: index = f"{subpage}/{len(pages)}" p[0] = f"{p[0]:<34.34}{ttxcolour.white()}{index:>5}" line = 4 for r in p: if len(r): page.addline(line, r) line += 1 sport_footer(page, 'Cricket') page.save() return links
def weatherindex(regionhead, ukhead): cfg = _config["weather"] page = ttxpage.TeletextPage("Weather Index", cfg["index"]) regionheads = textwrap.wrap(page.fixup(regionhead), 35) regionhead = f"{regionheads[0]:<35.35}" regionheads = regionheads[1:] headline = "WEATHER NEWS:¬" + page.fixup(ukhead) headlines = textwrap.wrap(headline, 39) for i in range(len(headlines)): l = headlines[i] if i == 0: l = ttxcolour.yellow() + l.replace("¬", ttxcolour.green()) elif i == len(headlines) - 1: l = ( ttxcolour.green() + f"{l:<35.35}" + ttxcolour.yellow() + f"{cfg['maps']:03x}" ) else: l = ttxcolour.green() + l headlines[i] = l header = [ "␗j#3kj#3kj#3k␔␝␑␓h44|h<h<|(|$|h4|$|l ", "␗j $kj $kj 'k␔␝␑␓*uu?jwj7␡ ␡ ␡k5␡1␡k4 ", '␗"###"###"###␔////,,.-,-.,/,/,-.,.,-.///', ] middle = [ "␃UK␄````````````````````````````````````", "␆Forecast maps ␃401␆UK Cities 5 Day␃406", "␆Regions ␃402␆ ␃ ", "␆National ␃403␆ ␃ ", "␆Current Weather␃404 ", " ", ] attrib = "From the Met Office" attrib = f"{attrib:^39}"[2:] footer = headlines + [ "", ttxcolour.blue() + ttxcolour.colour(ttxcolour.NEW_BACK) + f"{ttxcolour.yellow()}{attrib}", ttxutils.decode("€AMaps €BRegional €COutlook €FMain Menu"), ] page.header(cfg["index"]) line = 1 for l in header: page.addline(line, ttxutils.decode(l)) line += 1 page.addline( line, ttxcolour.colour(ttxcolour.DOUBLE_HEIGHT) + regionhead + ttxcolour.yellow() + f"{cfg['regional']:03x}", ) line += 2 for l in regionheads: page.addline(line, " " + l) line += 1 line += 1 for l in middle: page.addline(line, ttxutils.decode(l)) line += 1 line = 25 - len(footer) for l in footer: page.addline(line, l) line += 1 page.addfasttext( cfg["maps"], cfg["regional"], cfg["national"], 0x100, 0x8FF, 0x199 ) page.save()
def weatherfiveday(W): cfg = _config["weather"] maximum = -9999 minimum = 9999 today = None entries = [] for city, num in fiveday_ids.items(): wx = W.loc_forecast(num, metoffer.DAILY).data if today is None: today = wx[0]["timestamp"][0] entry = [city] for i in range(5): wx_type = short_weathers.get(wx[i * 2]["Weather Type"][0], "N/A") max_temp = int(wx[i * 2]["Day Maximum Temperature"][0]) min_temp = int(wx[i * 2 + 1]["Night Minimum Temperature"][0]) date = wx[i * 2]["timestamp"][0] entry.append( f"{date.strftime('%a')}" f"{max_temp:>4}{min_temp:>4} {wx_type}" ) if max_temp > maximum: maximum = max_temp if min_temp < minimum: minimum = min_temp entries.append(entry) header = [ "␗j#3kj#3kj#3k␔␝␑␓h44|h<h<|(|$|h4|$|l ", "␗j $kj $kj 'k␔␝␑␓*uu?jwj7␡ ␡ ␡k5␡1␡k4 ", '␗"###"###"###␔////,,.-,-.,/,/,-.,.,-.///', ] temps_c = [] temps_f = [] steps = (maximum - minimum) / 10 if steps < 1: steps = 1 minimum = (minimum + maximum) // 2 - 5 for i in range(11): temp_c = round(minimum + i * steps) temp_f = round((temp_c * 1.8) + 32) c = str(temp_c) f = str(temp_f) l = max(len(c), len(f)) temps_c.append(f"{c:>{l}}") temps_f.append(f"{f:>{l}}") footer = [] back = ( ttxcolour.blue() + ttxcolour.colour(ttxcolour.NEW_BACK) + ttxcolour.yellow() ) footer.append(f"{back}C= " + " ".join(temps_c)) footer.append(f"{back}F= " + " ".join(temps_f)) footer.append( ttxutils.decode("€AUK map €B Sport €CWeather €FMain Menu") ) page = ttxpage.TeletextPage("Weather Five Day", cfg["fiveday"]) numpages = (len(entries) + 3) // 4 for sub in range(numpages): body = [] top = f"{sub+1}/{numpages}" body.append(f"{top:>39.39}") body.append( ttxcolour.yellow() + "UK FIVE DAY FORECAST FROM " + today.strftime("%e %b").strip() ) body.append(ttxcolour.green() + "max for 0600-1800 min for 1800-0600") body.append( ttxcolour.yellow() + " max min" + ttxcolour.white() + "C " + ttxcolour.yellow() + " max min" + ttxcolour.white() + "C" ) for i in range(2): count = 0 c1 = [] c2 = [] offset = (sub * 4) + i if offset < len(entries): c1 = entries[offset] offset = (sub * 4) + i + 2 if offset < len(entries): c2 = entries[offset] while len(c1) and len(c2): row = "" if count % 2: row += ttxcolour.cyan() else: row += ttxcolour.white() if len(c1): row += f"{c1[0]:<19.19} " c1 = c1[1:] if len(c2): row += c2[0] c2 = c2[1:] body.append(row) count += 1 body.append("") page.header(cfg["fiveday"], sub + 1, status=0xC000) line = 1 for l in header: page.addline(line, ttxutils.decode(l)) line += 1 for l in body: page.addline(line, l) line += 1 line = 25 - len(footer) for l in footer: page.addline(line, l) line += 1 page.addfasttext(cfg["maps"], 0x300, cfg["index"], 0x100, 0x8FF, 0x199) page.save()
def weatherobservations(W): cfg = _config["weather"] minimum = 9999 maximum = -9999 rows = [] timestamp = None for city, num in observation_ids.items(): obs = W.loc_observations(num, cache_hours=1).data time = None temp = '-' wind_speed = '-' wind_dir = '-' pressure = '-' trend = '-' weather_type = None for o in obs: if "timestamp" in o: time = o["timestamp"][0] if "Temperature" in o: temp = round(float(o["Temperature"][0])) if "Wind Speed" in o: wind_speed = o["Wind Speed"][0] if "Wind Direction" in o: wind_dir = o["Wind Direction"][0] if "Pressure" in o: pressure = o["Pressure"][0] if "Pressure Tendency" in o: trend = o["Pressure Tendency"][0] if "Weather Type" in o: weather_type = o["Weather Type"][0] if len(rows) % 2 == 1: row_colour = ttxcolour.white() else: row_colour = ttxcolour.cyan() if trend == "F": trend_colour = ttxcolour.green() elif trend == "S": trend_colour = ttxcolour.white() else: trend_colour = ttxcolour.cyan() row = f"{row_colour}{city:<12.12}{temp:>4}{wind_dir:>4}{wind_speed:>3}" row += f"{pressure:>6}{trend_colour}{trend}{row_colour}" if weather_type is not None: row += short_weathers[weather_type] else: row += "n/a" rows.append(row) if time is not None and (timestamp is None or time > timestamp): timestamp = time if temp and temp != '-': if temp < minimum: minimum = temp if temp > maximum: maximum = temp header = [ "␗j#3kj#3kj#3k␔␝␑␓h44|h<h<|(|$|h4|$|l ", "␗j $kj $kj 'k␔␝␑␓*uu?jwj7␡ ␡ ␡k5␡1␡k4 ", '␗"###"###"###␔////,,.-,-.,/,/,-.,.,-.///', ] temps_c = [] temps_f = [] steps = (maximum - minimum) / 10 if steps < 1: steps = 1 minimum = (minimum + maximum) // 2 - 5 for i in range(11): temp_c = round(minimum + i * steps) temp_f = round((temp_c * 1.8) + 32) c = str(temp_c) f = str(temp_f) l = max(len(c), len(f)) temps_c.append(f"{c:>{l}}") temps_f.append(f"{f:>{l}}") footer = [] footer.append(ttxutils.decode(" ␃pressure␆R␃rising␇S␃steady␂F␃falling")) footer.append("") back = ( ttxcolour.blue() + ttxcolour.colour(ttxcolour.NEW_BACK) + ttxcolour.yellow() ) footer.append(f"{back}C= " + " ".join(temps_c)) footer.append(f"{back}F= " + " ".join(temps_f)) footer.append( ttxutils.decode("€AUK 5 day€B Sport €CWeather €FMain Menu") ) page = ttxpage.TeletextPage("Weather Reports", cfg["observations"]) for subpage in (1, 2, 3): body = [] top = f"{subpage}/3" body.append(f"{top:>39.39}") time = timestamp.strftime("%H%M") body.append(f"{ttxcolour.yellow()}CURRENT UK WEATHER: Report at {time}") body.append("") body.append(ttxutils.decode(" ␃temp wind pres")) body.append(ttxutils.decode(" ␇C mph mB")) base = (subpage - 1) * 10 for l in rows[base : base + 10]: body.append(l) page.header(cfg["observations"], subpage, status=0xC000) line = 1 for l in header: page.addline(line, ttxutils.decode(l)) line += 1 for l in body: page.addline(line, l) line += 1 line = 25 - len(footer) for l in footer: page.addline(line, l) line += 1 page.addfasttext( cfg["fiveday"], 0x300, cfg["index"], 0x100, 0x8FF, 0x199 ) subpage += 1 page.save()