Dateien hochladen nach „“

The script is showing the tv program starting now and in the next hour, defaulttime is your actual system time.
This commit is contained in:
HDValentin 2023-10-25 22:31:44 +02:00
parent 160a7bae23
commit 3430cdf852

91
tv_program_now.py Normal file
View File

@ -0,0 +1,91 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import time
import locale
from datetime import date, datetime, timedelta
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
}
# Get the current time
#current_time = datetime.now().strftime("%H:%M")
current_time = format(datetime.now(), "%H:%M")
# Calculate the default end time (start time + 1 hour)
# default_end_time = (datetime.strptime(current_time, "%H:%M") + timedelta(hours=0.5)).strftime("%H:%M")
default_end_time = format(datetime.now() + timedelta(hours=1), "%H:%M")
myday = f"{date.today():%d}"
print("Day:", myday)
print("Starttime:", current_time)
print("Endtime:", default_end_time)
# Create an argument parser
parser = argparse.ArgumentParser(description="TV Program Viewer")
parser.add_argument(
"--start-time",
type=str,
default=current_time,
help="Start time in HH:MM format (default: current time)",
)
parser.add_argument(
"--end-time",
type=str,
default=default_end_time,
help="End time in HH:MM format (default: start time + 1 hour)",
)
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))
# Split the start time into hours and minutes
start_hours, start_minutes = map(int, start.split(":"))
day = time.strftime("%d", time.localtime(int(st)))
if day == myday and start_time <= f"{start_hours:02}:{start_minutes:02}" <= end_time:
data.append([start, title])
return data
def makeList(start_time, end_time):
print("Channels:", len(dictList))
table.append(["Channel", f"TV Shows from {start_time} to {end_time}"])
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)
# print("Start:", args.start_time)
# print("Ende:", args.end_time)