From 748579346afe610b108bb90b51d1d9966215da06 Mon Sep 17 00:00:00 2001 From: iAmInAction <83808704+iAmInActions@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:57:25 +0200 Subject: [PATCH] =?UTF-8?q?ZDF=20Teletext=20viewer=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ein einfaches Teletextbetrachtungsprogram in Python und Bash für Linux --- zdftext/teletext.sh | 23 ++++++++++++++ zdftext/teletext2ansi.py | 66 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 zdftext/teletext.sh create mode 100644 zdftext/teletext2ansi.py diff --git a/zdftext/teletext.sh b/zdftext/teletext.sh new file mode 100644 index 0000000..27bd545 --- /dev/null +++ b/zdftext/teletext.sh @@ -0,0 +1,23 @@ +#!/bin/bash +clear +echo "ZDF TeletextViewer für Linux" +echo "(c) 2024 mueller_minki" +echo "Freigegeben zum Bearbeiten und Teilen." +sleep 2 + +page=100 + +while [[ $(tput lines) -ne 26 ]] || [[ $(tput cols) -ne 41 ]] +do + clear + echo "Resize your terminal to 41x26" + sleep 0.2 +done + +while true +do + clear + curl "https://teletext.zdf.de/teletext/zdf/seiten/klassisch/$page.html" | python3 teletext2ansi.py + read -n 3 page + sleep 1 +done diff --git a/zdftext/teletext2ansi.py b/zdftext/teletext2ansi.py new file mode 100644 index 0000000..00d24ab --- /dev/null +++ b/zdftext/teletext2ansi.py @@ -0,0 +1,66 @@ +import sys +from bs4 import BeautifulSoup + +# ANSI color codes +ansi_colors = { + 'c000000': '\033[30m', + 'cFFFFFF': '\033[37m', + 'cFFFF00': '\033[33m', + 'c00FF00': '\033[32m', + 'c0000FF': '\033[34m', + 'c00FF00': '\033[32m', + 'bc000000': '\033[40m', + 'bcFFFFFF': '\033[47m', + 'bcFFFF00': '\033[43m', + 'bc00FF00': '\033[42m', + 'bc0000FF': '\033[44m' +} + +# ANSI reset code +ansi_reset = '\033[0m' + +# Function to convert teletextlinedrawregular characters to ANSI blocks +def convert_line_draw(char): + if char == '/': + return '\u2588' # Full block + elif char == ',': + return '\u2584' # Lower half block + elif char == "'": + return '\u2580' # Upper half block + else: + return '\u2588' # Default to full block for other characters + +# Function to process span tags +def process_span(span): + classes = span.get('class', []) + style = '' + + for cls in classes: + if cls in ansi_colors: + style += ansi_colors[cls] + + content = span.text + if 'teletextlinedrawregular' in classes: + content = ''.join(convert_line_draw(char) for char in content) + + return style + content + ansi_reset + +# Read the HTML file from stdin +html_content = sys.stdin.read() + +# Parse the HTML content using BeautifulSoup +soup = BeautifulSoup(html_content, 'html.parser') + +# Find the content div +content_div = soup.find('div', id='content') + +if content_div: + # Process each row within the content div + for row_div in content_div.find_all('div', class_='row'): + row_content = '' + for span in row_div.find_all('span'): + row_content += process_span(span) + # Print the row content + print(row_content) +else: + print("No content found with id 'content'.", file=sys.stderr)