ZDF Teletext viewer hinzugefügt

Ein einfaches Teletextbetrachtungsprogram in Python und Bash für Linux
This commit is contained in:
iAmInAction 2024-06-24 13:57:25 +02:00 committed by GitHub
parent 8064ea0626
commit 748579346a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 89 additions and 0 deletions

23
zdftext/teletext.sh Normal file
View File

@ -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

66
zdftext/teletext2ansi.py Normal file
View File

@ -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)