From bead47ab24fa3ccd17c65b4991be8400bc10da3a Mon Sep 17 00:00:00 2001 From: HDValentin Date: Sat, 21 Oct 2023 23:38:15 +0200 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9E=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python script that shows the tv programm in console. --- tv_program.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tv_program.py diff --git a/tv_program.py b/tv_program.py new file mode 100644 index 0000000..e627d30 --- /dev/null +++ b/tv_program.py @@ -0,0 +1,81 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +import requests +import time +import locale +from datetime import date +from tabulate import tabulate +import argparse + +loc = locale.getlocale() +locale.setlocale(locale.LC_ALL, loc) +dt = f"{date.today():%-d.%B %Y}" +table = [] + +dictList = { + 'ard': 71, 'zdf': 37, 'zdf neo': 659, 'zdf info': 276, 'arte': 58, 'wdr': 46, 'ndr': 47, + 'mdr': 48, 'hr': 49, 'swr': 10142, 'br': 51, 'rbb': 52, '3sat': 56, 'alpha': 104, + 'kika': 57, 'phoenix': 194, 'tagesschau 24': 100, 'one': 146, 'rtl': 38, 'sat 1': 39, + 'pro 7': 40, 'rtl plus': 12033, 'kabel 1': 44, 'rtl 2': 41, 'vox': 42, 'rtl nitro': 763, + 'n24 doku': 12045, 'kabel 1 doku': 12043, 'sport 1': 64, 'super rtl': 43, + 'sat 1 gold': 774, 'vox up': 12125, 'sixx': 694, 'servus tv': 660, + 'welt': 175, 'orf 1': 54, 'orf 2': 55, 'orf 3': 56, 'tele 5': 277, '7maxx': 783, + 'dmaxx': 507, 'dw': 300, 'fox': 565, 'srf 1': 59, 'srf 2': 60 +} + +myday = f"{date.today():%d}" +print("Day:", myday) + +# Define the time range (modify as needed) +default_start_time = 2015 # 5:30 AM +default_end_time = 2030 # 4:00 PM + +# Create an argument parser +parser = argparse.ArgumentParser(description="TV Program Viewer") +parser.add_argument( + "--start-time", + type=int, + default=default_start_time, + help="Start time in HHMM format (e.g., 0530 for 5:30 AM)", +) +parser.add_argument( + "--end-time", + type=int, + default=default_end_time, + help="End time in HHMM format (e.g., 2030 for 8:30 PM)", +) +args = parser.parse_args() + +response = requests.get('http://mobile.hoerzu.de/programbystation') +response_json = response.json() + +def getValues(id, start_time, end_time): + for i in response_json: + if i['id'] == id: + pr = i['broadcasts'] + data = [] + for a in pr: + title = a.get('title') + st = a.get('startTime') + d = a.get('duration') + start = time.strftime("%-H:%M", time.localtime(st)) + start_time_int = int(start.replace(":", "")) + day = time.strftime("%d", time.localtime(int(st))) + if day == myday and start_time <= start_time_int < end_time: + data.append([start, title]) + return data + +def makeList(start_time, end_time): + print("Channel:", len(dictList)) + table.append(["Channel", f"TV Shows from {start_time // 100}:{start_time % 100:02d} to {end_time // 100}:{end_time % 100:02d}"]) + for ch in dictList: + data = [ch.upper()] + channel_data = getValues(dictList.get(ch), start_time, end_time) + if channel_data: + for item in channel_data: + data.extend(item) + table.append(data) + + print(tabulate(table, headers="firstrow", tablefmt="pretty")) + +makeList(args.start_time, args.end_time)