From b25d48fe6423315fd796d854904ea68227ca20b8 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:07:03 +0200
Subject: [PATCH 01/61] Update Config.py - fix type hinting
---
tvguide/Config.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tvguide/Config.py b/tvguide/Config.py
index 8034bf4..6a8436f 100644
--- a/tvguide/Config.py
+++ b/tvguide/Config.py
@@ -1,4 +1,6 @@
+from typing import List
from configparser import ConfigParser
+
from .filemanager import Filemanager
@@ -17,7 +19,7 @@ def write(file_name: str, config: ConfigParser) -> None:
config.write(default_file)
@staticmethod
- def get_defaults_user_channels() -> list:
+ def get_defaults_user_channels() -> List[str]:
config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
defaultChannels = config['DefaultChannels']['channels']
@@ -25,7 +27,7 @@ def get_defaults_user_channels() -> list:
return defaultChannels.split(',')
@staticmethod
- def change_defaults_user_channels(new_defaults: list) -> None:
+ def change_defaults_user_channels(new_defaults: List[str]) -> None:
config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
config['DefaultChannels']['channels'] = ','.join(new_defaults)
From fe81f8c3a86ab668ac8e0fc2d0998da93025a74d Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:08:19 +0200
Subject: [PATCH 02/61] Temporarily rename Config.py
---
tvguide/{Config.py => config_1.py} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename tvguide/{Config.py => config_1.py} (100%)
diff --git a/tvguide/Config.py b/tvguide/config_1.py
similarity index 100%
rename from tvguide/Config.py
rename to tvguide/config_1.py
From 152325b3b72087fe9c4b8dc46b326df124ce75ef Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:15:01 +0200
Subject: [PATCH 03/61] Rename config_1.py to config.py and rename class Config
to ConfigManager
---
main.py | 8 ++++----
tvguide/__init__.py | 2 +-
tvguide/{config_1.py => config.py} | 20 ++++++++++----------
tvguide/format.py | 4 ++--
tvguide/tv.py | 6 +++---
5 files changed, 20 insertions(+), 20 deletions(-)
rename tvguide/{config_1.py => config.py} (66%)
diff --git a/main.py b/main.py
index fffd68b..2cb49db 100644
--- a/main.py
+++ b/main.py
@@ -48,21 +48,21 @@ def print_program_all(data_source: dict, user_channels: list) -> None:
def change_defaults(args, data: dict):
if args.default_channels:
- tv.Config.change_defaults_user_channels(args.default_channels)
+ tv.ConfigManager.change_defaults_user_channels(args.default_channels)
default_channels_string = ", ".join(args.default_channels).upper()
print(f"Changed default channel(s) to: {default_channels_string}")
if args.default_space_seperator:
- tv.Config.change_space_seperator(args.default_space_seperator)
+ tv.ConfigManager.change_space_seperator(args.default_space_seperator)
print(f"Changed space seperator to: {args.default_space_seperator}")
if args.justify_length:
- tv.Config.change_justify_length(args.justify_length)
+ tv.ConfigManager.change_justify_length(args.justify_length)
print(f"Changed justify length to: {args.justify_length}")
if not args.channel:
- args.channel = tv.Config.get_defaults_user_channels()
default_channels_string = ", ".join(args.channel).upper()
+ args.channel = tv.ConfigManager.get_defaults_user_channels()
print(f"No channel(s) chosen: using default channels ({default_channels_string})")
elif args.channel[0].lower() == "all":
args.channel = [channel for channel in data.keys()]
diff --git a/tvguide/__init__.py b/tvguide/__init__.py
index 135f832..1c5b7fa 100644
--- a/tvguide/__init__.py
+++ b/tvguide/__init__.py
@@ -1,4 +1,4 @@
from .format import Format
from .argument import argparse_setup
from .API import API
-from .Config import Config
\ No newline at end of file
+from .config import ConfigManager
diff --git a/tvguide/config_1.py b/tvguide/config.py
similarity index 66%
rename from tvguide/config_1.py
rename to tvguide/config.py
index 6a8436f..c92c935 100644
--- a/tvguide/config_1.py
+++ b/tvguide/config.py
@@ -4,7 +4,7 @@
from .filemanager import Filemanager
-class Config:
+class ConfigManager:
@staticmethod
def read(file_name: str) -> ConfigParser:
"""Read user settings in {file_name}.ini"""
@@ -20,7 +20,7 @@ def write(file_name: str, config: ConfigParser) -> None:
@staticmethod
def get_defaults_user_channels() -> List[str]:
- config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
defaultChannels = config['DefaultChannels']['channels']
@@ -28,36 +28,36 @@ def get_defaults_user_channels() -> List[str]:
@staticmethod
def change_defaults_user_channels(new_defaults: List[str]) -> None:
- config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
config['DefaultChannels']['channels'] = ','.join(new_defaults)
- Config.write('defaults.ini', config)
+ ConfigManager.write('defaults.ini', config)
@staticmethod
def get_space_seperator() -> str:
- config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
return config['Misc']['spaceSeperator']
@staticmethod
def change_space_seperator(new_space_seperator: str) -> None:
- config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
config['Misc']['spaceSeperator'] = new_space_seperator
- Config.write('defaults.ini', config)
+ ConfigManager.write('defaults.ini', config)
@staticmethod
def get_justify_length() -> int:
- config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
return int(config['Misc']['justifyLength'])
@staticmethod
def change_justify_length(new_length: int):
- config = Config.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
config['Misc']['justifyLength'] = new_length
- Config.write('defaults.ini', config)
+ ConfigManager.write('defaults.ini', config)
diff --git a/tvguide/format.py b/tvguide/format.py
index a4a76a1..b83d2e5 100644
--- a/tvguide/format.py
+++ b/tvguide/format.py
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta, timezone
-from .Config import Config
+from .config import ConfigManager
import pytz
@@ -37,7 +37,7 @@ def convert_unix_time(unix_time: int, toShow: bool):
def user_search(search: str) -> str:
search = search.lower()
- spaceSeperator = Config.get_space_seperator()
+ spaceSeperator = ConfigManager.get_space_seperator()
return search.replace(spaceSeperator, ' ')
diff --git a/tvguide/tv.py b/tvguide/tv.py
index b634a5d..0980d5b 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -1,6 +1,6 @@
from datetime import datetime
from .const import CHANNEL_NUMBER_INDEX
-from .format import Format, Config
+from .format import Format, ConfigManager
import time
@@ -104,7 +104,7 @@ def start_time_and_title(self) -> str:
@property
def time_and_title_and_category(self) -> str:
time_and_title = f"{self.time_start_show} - {self.time_stop_show} > {self.title}"
- justify_length = Config.get_justify_length()
+ justify_length = ConfigManager.get_justify_length()
if len(time_and_title) > justify_length:
time_and_title_cut = f"{time_and_title[:justify_length]}..."
@@ -116,7 +116,7 @@ def time_and_title_and_category(self) -> str:
@property
def start_time_and_title_and_category(self) -> str:
time_and_title = f"{self.time_start_show} > {self.title}"
- justify_length = Config.get_justify_length()
+ justify_length = ConfigManager.get_justify_length()
if len(time_and_title) > justify_length:
time_and_title_cut = f"{time_and_title[:justify_length]}..."
From aee599ec599c4ee51c65dcdf3522784474299437 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:19:30 +0200
Subject: [PATCH 04/61] Change dest for argument --channel
---
main.py | 20 ++++++++++----------
tvguide/argument.py | 2 +-
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/main.py b/main.py
index 2cb49db..e12c832 100644
--- a/main.py
+++ b/main.py
@@ -60,29 +60,29 @@ def change_defaults(args, data: dict):
tv.ConfigManager.change_justify_length(args.justify_length)
print(f"Changed justify length to: {args.justify_length}")
- if not args.channel:
- default_channels_string = ", ".join(args.channel).upper()
- args.channel = tv.ConfigManager.get_defaults_user_channels()
+ if not args.channels:
+ default_channels_string = ", ".join(args.channels).upper()
+ args.channels = tv.ConfigManager.get_defaults_user_channels()
print(f"No channel(s) chosen: using default channels ({default_channels_string})")
- elif args.channel[0].lower() == "all":
- args.channel = [channel for channel in data.keys()]
+ elif args.channels[0].lower() == "all":
+ args.channels = [channel for channel in data.keys()]
def print_programs(args, data):
if args.now:
- print_currently_running(data, args.channel)
+ print_currently_running(data, args.channels)
if args.time:
- print_program_times(data, args.channel, args.time)
+ print_program_times(data, args.channels, args.time)
if args.category:
- print_program_categories(data, args.channel, args.category)
+ print_program_categories(data, args.channels, args.category)
if args.search:
- print_program_searches(data, args.channel, args.search)
+ print_program_searches(data, args.channels, args.search)
if args.all:
- print_program_all(data, args.channel)
+ print_program_all(data, args.channels)
def main():
diff --git a/tvguide/argument.py b/tvguide/argument.py
index 0159eb0..6174b32 100644
--- a/tvguide/argument.py
+++ b/tvguide/argument.py
@@ -8,7 +8,7 @@ def argparse_setup() -> ArgumentParser.parse_args:
parser.add_argument(
'-c',
'--channel',
- dest='channel',
+ dest='channels',
help='the channel with the user want to see programs from',
nargs="*",
action="extend",
From 0fc805a3357d41ea7ddbdff6dd2750e831ee2373 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:21:20 +0200
Subject: [PATCH 05/61] Rename class API to ApiManager
---
main.py | 4 ++--
tvguide/API.py | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/main.py b/main.py
index e12c832..fbd7a3a 100644
--- a/main.py
+++ b/main.py
@@ -88,9 +88,9 @@ def print_programs(args, data):
def main():
args = tv.argparse_setup()
- api_data = tv.API.get_data(args.day)
+ api_data = tv.ApiManager.get_data(args.day)
- my_data = tv.API.format_data(api_data, args.verbose)
+ my_data = tv.ApiManager.format_data(api_data, args.verbose)
change_defaults(args, my_data)
diff --git a/tvguide/API.py b/tvguide/API.py
index 03413dd..944c73a 100644
--- a/tvguide/API.py
+++ b/tvguide/API.py
@@ -4,7 +4,7 @@
from .tv import Channel
-class API:
+class ApiManager:
@staticmethod
def get_link(relative_date: int) -> str:
return API_LINK.replace("{date}", Format.get_specified_date(relative_date))
@@ -13,7 +13,7 @@ def get_link(relative_date: int) -> str:
def get_data(relative_day: int) -> dict:
"""Get formatted data from API"""
response = requests.get(
- API.get_link(relative_day),
+ ApiManager.get_link(relative_day),
headers=REQUEST_HEADER,
cookies=REQUEST_COOKIES
)
From 81e0be02981ba3fcb5ca09bc603fd9046c0fe496 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:23:42 +0200
Subject: [PATCH 06/61] Temporarily rename API.py to api_temp.py
---
tvguide/{API.py => api_temp.py} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename tvguide/{API.py => api_temp.py} (100%)
diff --git a/tvguide/API.py b/tvguide/api_temp.py
similarity index 100%
rename from tvguide/API.py
rename to tvguide/api_temp.py
From 9c3431759f575cd7b352c894f0c63e4c589b51d9 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:24:07 +0200
Subject: [PATCH 07/61] Rename api_temp.py to api.py
---
tvguide/{api_temp.py => api.py} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename tvguide/{api_temp.py => api.py} (100%)
diff --git a/tvguide/api_temp.py b/tvguide/api.py
similarity index 100%
rename from tvguide/api_temp.py
rename to tvguide/api.py
From 1cc4a44d200856fb55945abeb4eee0f55d4cc715 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:27:12 +0200
Subject: [PATCH 08/61] Make api.py more readable and format with black
---
tvguide/api.py | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/tvguide/api.py b/tvguide/api.py
index 944c73a..5bc5ceb 100644
--- a/tvguide/api.py
+++ b/tvguide/api.py
@@ -7,16 +7,14 @@
class ApiManager:
@staticmethod
def get_link(relative_date: int) -> str:
- return API_LINK.replace("{date}", Format.get_specified_date(relative_date))
+ date = Format.get_specified_date(relative_date)
+ return API_LINK.replace("{date}", date)
@staticmethod
def get_data(relative_day: int) -> dict:
"""Get formatted data from API"""
- response = requests.get(
- ApiManager.get_link(relative_day),
- headers=REQUEST_HEADER,
- cookies=REQUEST_COOKIES
- )
+ api_link = ApiManager.get_link(relative_day)
+ response = requests.get(api_link, headers=REQUEST_HEADER, cookies=REQUEST_COOKIES)
return response.json()
From de4d355a54b9d9f3c44308ca272595c59da92e03 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sat, 15 Oct 2022 23:27:20 +0200
Subject: [PATCH 09/61] Update __init__.py
---
tvguide/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvguide/__init__.py b/tvguide/__init__.py
index 1c5b7fa..4f8eaa2 100644
--- a/tvguide/__init__.py
+++ b/tvguide/__init__.py
@@ -1,4 +1,4 @@
from .format import Format
from .argument import argparse_setup
-from .API import API
+from .api import ApiManager
from .config import ConfigManager
From 2466bf5e029e7b9b54ea14d81d64c4635de781b5 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 08:07:28 +0200
Subject: [PATCH 10/61] Create tvguide.py
---
tvguide/__init__.py | 1 +
tvguide/tvguide.py | 47 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
create mode 100644 tvguide/tvguide.py
diff --git a/tvguide/__init__.py b/tvguide/__init__.py
index 4f8eaa2..4e4a10c 100644
--- a/tvguide/__init__.py
+++ b/tvguide/__init__.py
@@ -2,3 +2,4 @@
from .argument import argparse_setup
from .api import ApiManager
from .config import ConfigManager
+from .tvguide import TvGuide
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
new file mode 100644
index 0000000..8e582dc
--- /dev/null
+++ b/tvguide/tvguide.py
@@ -0,0 +1,47 @@
+from typing import List
+import argparse
+from tvguide.config import ConfigManager
+
+from tvguide.tv import Channel
+
+
+class TvGuide:
+ def __init__(self) -> None:
+ self.show_all_channels = False
+ self.input_channels: List[str] = []
+ self.channels: List[Channel] = None
+
+ def parse_arguments(self, args: argparse.Namespace) -> None:
+ if args.default_channels:
+ self._change_default_channels(args.default_channels)
+
+ if args.default_space_seperator:
+ self._change_default_space_seperator(args.default_space_seperator)
+
+ if args.justify_length:
+ self._change_default_justify_length(args.justify_length)
+
+ if not args.channels:
+ self.input_channels = self.get_default_channels()
+ elif "all" in args.channels:
+ self.show_all_channels = True
+ else:
+ self.input_channels = args.channels
+
+ def _change_default_channels(self, channels: List[str]) -> None:
+ ConfigManager.change_defaults_user_channels(channels)
+
+ def _change_default_space_seperator(self, space_seperator: str) -> None:
+ ConfigManager.change_space_seperator(space_seperator)
+
+ def _change_default_justify_length(self, justify_length: int) -> None:
+ ConfigManager.change_justify_length(justify_length)
+
+ def get_default_channels(self) -> List[str]:
+ return ConfigManager.get_defaults_user_channels()
+
+ def get_default_space_seperator(self) -> str:
+ return ConfigManager.get_space_seperator()
+
+ def get_default_justify_length(self) -> int:
+ return ConfigManager.get_justify_length()
From bbe78b1d9e9560c6539145f2ca4c229a6068a6b3 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 20:19:23 +0200
Subject: [PATCH 11/61] Fix
---
main.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/main.py b/main.py
index fbd7a3a..e5e4766 100644
--- a/main.py
+++ b/main.py
@@ -61,8 +61,8 @@ def change_defaults(args, data: dict):
print(f"Changed justify length to: {args.justify_length}")
if not args.channels:
- default_channels_string = ", ".join(args.channels).upper()
args.channels = tv.ConfigManager.get_defaults_user_channels()
+ default_channels_string = ", ".join(args.channels).upper()
print(f"No channel(s) chosen: using default channels ({default_channels_string})")
elif args.channels[0].lower() == "all":
args.channels = [channel for channel in data.keys()]
From 78e6e2a7e1176024ec4e4d4691ff780929469739 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 20:23:05 +0200
Subject: [PATCH 12/61] Use requests_cache to cache requests
---
.gitignore | 3 ++-
requirements.txt | 3 ++-
tvguide/api.py | 3 +++
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
index 6b253df..20b70cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
__pycache__/
-.vscode/
\ No newline at end of file
+.vscode/
+api_cache/
diff --git a/requirements.txt b/requirements.txt
index 4261e68..ad40ca9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +1,2 @@
-requests==2.24.0
\ No newline at end of file
+requests>=2.24.0
+requests-cache>=0.9.6
\ No newline at end of file
diff --git a/tvguide/api.py b/tvguide/api.py
index 5bc5ceb..d18b6d6 100644
--- a/tvguide/api.py
+++ b/tvguide/api.py
@@ -1,8 +1,11 @@
import requests
+import requests_cache
from .const import API_LINK, REQUEST_HEADER, REQUEST_COOKIES
from .format import Format
from .tv import Channel
+requests_cache.install_cache(cache_name="api_cache", expire_after=120, backend="sqlite")
+
class ApiManager:
@staticmethod
From 9cdbcd4e33f9d948e4e98a9289a9e162f690771b Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 21:23:13 +0200
Subject: [PATCH 13/61] Use filesystem as backend to requests_cache
---
tvguide/api.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvguide/api.py b/tvguide/api.py
index d18b6d6..5ebd41b 100644
--- a/tvguide/api.py
+++ b/tvguide/api.py
@@ -4,7 +4,7 @@
from .format import Format
from .tv import Channel
-requests_cache.install_cache(cache_name="api_cache", expire_after=120, backend="sqlite")
+requests_cache.install_cache(cache_name="api_cache", expire_after=120, backend="filesystem")
class ApiManager:
From f6fee0734aed266e1977a9f847cea8ee243c564e Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 21:23:55 +0200
Subject: [PATCH 14/61] Update Filemanager to have root_path and
defaults_ini_path as properties
---
tvguide/config.py | 18 +++++++++---------
tvguide/filemanager.py | 7 +++----
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/tvguide/config.py b/tvguide/config.py
index c92c935..764c07b 100644
--- a/tvguide/config.py
+++ b/tvguide/config.py
@@ -20,7 +20,7 @@ def write(file_name: str, config: ConfigParser) -> None:
@staticmethod
def get_defaults_user_channels() -> List[str]:
- config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(Filemanager.defaults_ini_path)
defaultChannels = config['DefaultChannels']['channels']
@@ -28,36 +28,36 @@ def get_defaults_user_channels() -> List[str]:
@staticmethod
def change_defaults_user_channels(new_defaults: List[str]) -> None:
- config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(Filemanager.defaults_ini_path)
config['DefaultChannels']['channels'] = ','.join(new_defaults)
- ConfigManager.write('defaults.ini', config)
+ ConfigManager.write(Filemanager.defaults_ini_path, config)
@staticmethod
def get_space_seperator() -> str:
- config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(Filemanager.defaults_ini_path)
return config['Misc']['spaceSeperator']
@staticmethod
def change_space_seperator(new_space_seperator: str) -> None:
- config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(Filemanager.defaults_ini_path)
config['Misc']['spaceSeperator'] = new_space_seperator
- ConfigManager.write('defaults.ini', config)
+ ConfigManager.write(Filemanager.defaults_ini_path, config)
@staticmethod
def get_justify_length() -> int:
- config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(Filemanager.defaults_ini_path)
return int(config['Misc']['justifyLength'])
@staticmethod
def change_justify_length(new_length: int):
- config = ConfigManager.read(f'{Filemanager.get_root_path()}/defaults.ini')
+ config = ConfigManager.read(Filemanager.defaults_ini_path)
config['Misc']['justifyLength'] = new_length
- ConfigManager.write('defaults.ini', config)
+ ConfigManager.write(Filemanager.defaults_ini_path, config)
diff --git a/tvguide/filemanager.py b/tvguide/filemanager.py
index 8541b91..db00b2a 100644
--- a/tvguide/filemanager.py
+++ b/tvguide/filemanager.py
@@ -1,7 +1,6 @@
import pathlib
class Filemanager:
- @staticmethod
- def get_root_path():
- """Return root path of this repository"""
- return pathlib.Path(__file__).parent.absolute()
+ # root path of this repository
+ root_path = pathlib.Path(__file__).parent.parent.absolute()
+ defaults_ini_path = f"{root_path}/tvguide/defaults.ini"
From 2b60744e06dd073d5d160cb10624b33f4df40a60 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 21:24:41 +0200
Subject: [PATCH 15/61] Add type hint in class Channel
---
tvguide/tv.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 0980d5b..2d197a7 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -1,3 +1,4 @@
+from typing import List
from datetime import datetime
from .const import CHANNEL_NUMBER_INDEX
from .format import Format, ConfigManager
@@ -9,12 +10,12 @@ def __init__(self, channel_info: dict, verbose: bool = False) -> None:
self.verbose = verbose
self.id = channel_info['id']
self.name = CHANNEL_NUMBER_INDEX[self.id]
- self.programs = []
+ self.programs: List[Program] = []
self.format_program_info(channel_info)
def format_program_info(self, channel_info: dict) -> None:
- for program in channel_info['programs']:
- self.add_program(program)
+ for program_dict in channel_info['programs']:
+ self.add_program(program_dict)
def add_program(self, program_info: dict) -> None:
new_program = Program(program_info, self.verbose)
From afb2928b80e6c8b018044c198e88876d85299035 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 21:32:46 +0200
Subject: [PATCH 16/61] Update class TvGuide
- Add properties
- Update method parse_arguments
- Add methods parse_api_data, print_programs and get_channels
---
tvguide/tvguide.py | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 8e582dc..81bbc2a 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -7,11 +7,25 @@
class TvGuide:
def __init__(self) -> None:
+ self.relative_date = 0
+ self.verbose = False
+ self.show_now = False
self.show_all_channels = False
+ self.show_all_programs = False
+ self.show_time = False
+ self.input_time = None
+ self.search = False
self.input_channels: List[str] = []
- self.channels: List[Channel] = None
+ self.search_terms: List[str] = []
+ self.channels: List[Channel] = []
def parse_arguments(self, args: argparse.Namespace) -> None:
+ self.verbose = args.verbose
+ self.show_now = args.now
+ self.relative_date = args.day
+ self.show_all_programs = args.all
+ self.search = args.search
+
if args.default_channels:
self._change_default_channels(args.default_channels)
@@ -21,6 +35,10 @@ def parse_arguments(self, args: argparse.Namespace) -> None:
if args.justify_length:
self._change_default_justify_length(args.justify_length)
+ if args.time:
+ self.show_time = True
+ self.input_time = args.time
+
if not args.channels:
self.input_channels = self.get_default_channels()
elif "all" in args.channels:
@@ -28,6 +46,20 @@ def parse_arguments(self, args: argparse.Namespace) -> None:
else:
self.input_channels = args.channels
+ def parse_api_data(self, api_data: dict) -> None:
+ for channel_dict in api_data:
+ channel = Channel(channel_dict, self.verbose)
+ self.channels.append(channel)
+
+ def print_programs(self) -> None:
+ channels = self._get_channels(self.input_channels)
+
+ for channel in channels:
+ print(channel.name)
+
+ def get_channels(self, channel_names: List[str]) -> List[Channel]:
+ return [channel for channel in self.channels if channel.name in channel_names]
+
def _change_default_channels(self, channels: List[str]) -> None:
ConfigManager.change_defaults_user_channels(channels)
From 870d8a8f94d51bc0fed50755e58079a4bf6fa85f Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 21:33:26 +0200
Subject: [PATCH 17/61] Create main_v2.py to test with
---
main_v2.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 main_v2.py
diff --git a/main_v2.py b/main_v2.py
new file mode 100644
index 0000000..9f8f6ac
--- /dev/null
+++ b/main_v2.py
@@ -0,0 +1,19 @@
+import tvguide as tv
+
+
+def main():
+ args = tv.argparse_setup()
+
+ tvguide = tv.TvGuide()
+
+ tvguide.parse_arguments(args)
+
+ api_data = tv.ApiManager.get_data(tvguide.relative_date)
+
+ tvguide.parse_api_data(api_data)
+
+ tvguide.print_programs()
+
+
+if __name__ == "__main__":
+ main()
From 1c71b1265a328533ca281bdf694bc4a44b5c9272 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 21:41:08 +0200
Subject: [PATCH 18/61] Fix method print_programs in class TvGuide
---
tvguide/tvguide.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 81bbc2a..e1dbf30 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -52,7 +52,7 @@ def parse_api_data(self, api_data: dict) -> None:
self.channels.append(channel)
def print_programs(self) -> None:
- channels = self._get_channels(self.input_channels)
+ channels = self.get_channels(self.input_channels)
for channel in channels:
print(channel.name)
From e237891aaf508166f91ad71c200ece5c64ec794f Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:12:13 +0200
Subject: [PATCH 19/61] Update values in CHANNEL_NUMBER_INDEX to replce "-"
with spaces and delete method Format.channel_name and delete line in README
about channel name
---
README.md | 1 -
tvguide/const.py | 130 +++++++++++++++++++++++-----------------------
tvguide/format.py | 7 +--
3 files changed, 66 insertions(+), 72 deletions(-)
diff --git a/README.md b/README.md
index 43e312f..6dd4f4e 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,6 @@ For example:
```
python3 main.py -c [channel_1] -c [channel_2]
```
-**OBS**: when specifing channels with a space such as "TV2 News", use a dash (-) instead of a space. E.g. "TV2 News" -> "TV2-News"
You can also specify "all" as the first channel to get all channels.
diff --git a/tvguide/const.py b/tvguide/const.py
index 41f086f..0dc8f19 100644
--- a/tvguide/const.py
+++ b/tvguide/const.py
@@ -110,98 +110,98 @@
"3": "tv2",
"5": "tv3",
"2": "dr2",
- "31": "tv2-charlie",
- "133": "tv2-news",
- "7": "kanal-5",
- "6": "tv3-plus",
- "4": "tv2-zulu",
- "10153": "dr-ramasjang",
- "8": "kanal-4",
- "77": "tv2-sport",
- "2147483561": "tv2-sport-x",
- "156": "tv3-sport",
- "10093": "tv3-puls",
+ "31": "tv2 charlie",
+ "133": "tv2 news",
+ "7": "kanal 5",
+ "6": "tv3 plus",
+ "4": "tv2 zulu",
+ "10153": "dr ramasjang",
+ "8": "kanal 4",
+ "77": "tv2 sport",
+ "2147483561": "tv2 sport x",
+ "156": "tv3 sport",
+ "10093": "tv3 puls",
"10066": "6eren",
- "14": "disney-channel",
- "12566": "tv2-fri",
- "10111": "canal-9",
- "70": "discovery-channel",
+ "14": "disney channel",
+ "12566": "tv2 fri",
+ "10111": "canal 9",
+ "70": "discovery channel",
"118": "tlc",
"153": "nickelodeon",
- "94": "national-geographic-channel",
- "12948": "tv3-max",
+ "94": "national geographic channel",
+ "12948": "tv3 max",
"185": "cartoon",
- "157": "disney-junior",
+ "157": "disney junior",
"15": "dk4",
"71": "mtv",
- "93": "animal-planet",
- "15049": "investigation-discovery",
+ "93": "animal planet",
+ "15049": "investigation discovery",
"219": "vh1",
- "37": "eurosport-2",
+ "37": "eurosport 2",
"248": "boomerang",
- "9": "viasat-film",
- "10": "viasat-film-action",
- "11": "viasat-film-hits",
- "12": "viasat-film-family",
- "19": "viasat-explorer",
- "20": "viasat-nature",
- "25": "c-more-first",
- "26": "c-more-hits",
- "39": "viasat-history",
- "74": "disney-xd",
- "111": "tv4-sverige",
- "116": "discovery-world",
+ "9": "viasat film",
+ "10": "viasat film action",
+ "11": "viasat film hits",
+ "12": "viasat film family",
+ "19": "viasat explorer",
+ "20": "viasat nature",
+ "25": "c more first",
+ "26": "c more hits",
+ "39": "viasat history",
+ "74": "disney xd",
+ "111": "tv4 sverige",
+ "116": "discovery world",
"129": "nrk2",
"130": "nrk1",
"135": "svt1",
"136": "sv2",
- "142": "tv2-norge",
- "147": "discovery-hd-showcase",
+ "142": "tv2 norge",
+ "147": "discovery hd showcase",
"161": "rtl",
"162": "ard",
"163": "zdf",
"164": "3sat",
- "165": "viasat-golf",
- "174": "eurosport-1",
+ "165": "viasat golf",
+ "174": "eurosport 1",
"181": "cnn",
"188": "ndr",
- "191": "bbc-world",
- "201": "c-more-series",
- "215": "travel-channel",
+ "191": "bbc world",
+ "201": "c more series",
+ "215": "travel channel",
"218": "vox",
- "221": "rtl-2",
- "240": "super-rtl",
- "570": "paramount-network",
+ "221": "rtl 2",
+ "240": "super rtl",
+ "570": "paramount network",
"687": "xee",
- "689": "viasat-ultra",
- "10061": "bbc-earth",
- "10070": "viasat-series",
+ "689": "viasat ultra",
+ "10061": "bbc earth",
+ "10070": "viasat series",
"10104": "arte",
- "10145": "sf-kanalen",
+ "10145": "sf kanalen",
"10159": "history",
- "10262": "kanal-hovedstaden",
+ "10262": "kanal hovedstaden",
"10341": "folketinget",
"10435": "tnt",
- "10455": "nickelodeon-junior",
+ "10455": "nickelodeon junior",
"10510": "sat1",
"10511": "prosieben",
"10621": "sport1",
- "11572": "national-geographic-wild",
- "11610": "tv2-nord-salto",
- "11611": "tv-midt-vest",
- "11612": "tv2-østjylland",
- "11613": "tv2-øst",
- "11614": "tv-syd",
- "11615": "tv-fyn",
+ "11572": "national geographic wild",
+ "11610": "tv2 nord salto",
+ "11611": "tv midt vest",
+ "11612": "tv2 østjylland",
+ "11613": "tv2 øst",
+ "11614": "tv syd",
+ "11615": "tv fyn",
"11616": "lorry",
- "11617": "tv2-bornholm",
- "12034": "tv3-sport-2-hd",
- "12396": "bbc-brit",
- "12697": "tv5-monde-europe",
- "15032": "national-geographic-people",
- "15129": "comedy-central",
- "2147483566": "cs-go",
- "2147483567": "zulu-comedy",
+ "11617": "tv2 bornholm",
+ "12034": "tv3 sport 2 hd",
+ "12396": "bbc brit",
+ "12697": "tv5 monde europe",
+ "15032": "national geographic people",
+ "15129": "comedy central",
+ "2147483566": "cs go",
+ "2147483567": "zulu comedy",
"2147483568": "oiii",
- "117": "discovery-science",
+ "117": "discovery science",
}
diff --git a/tvguide/format.py b/tvguide/format.py
index b83d2e5..b75d95b 100644
--- a/tvguide/format.py
+++ b/tvguide/format.py
@@ -4,11 +4,6 @@
class Format:
- @staticmethod
- def channel_name(name: str) -> str:
- name = name.replace("-", " ")
- return name.upper()
-
@staticmethod
def user_time(time: str) -> int:
return int(time.replace(":", ""))
@@ -40,7 +35,7 @@ def user_search(search: str) -> str:
spaceSeperator = ConfigManager.get_space_seperator()
return search.replace(spaceSeperator, ' ')
-
+
@staticmethod
def program_time_stop(time_start: int, time_stop: int) -> int:
if time_start > time_stop:
From 8072b1edcb32243337889f1c40d453c80de1ab6b Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:13:02 +0200
Subject: [PATCH 20/61] Delete duplicate print statements in class Channel
---
tvguide/tv.py | 5 -----
1 file changed, 5 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 2d197a7..1d5b2a4 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -22,13 +22,11 @@ def add_program(self, program_info: dict) -> None:
self.programs.append(new_program)
def print_all_programs(self) -> None:
- print(f"\n{Format.channel_name(self.name)}:")
for program in self.programs:
print(program.start_time_and_title)
print()
def print_searches(self, search_terms: list) -> None:
- print(f"\n{Format.channel_name(self.name)}:")
for program in self.programs:
for search in search_terms:
search = Format.user_search(search)
@@ -38,7 +36,6 @@ def print_searches(self, search_terms: list) -> None:
print()
def print_categories(self, categories: list) -> None:
- print(f"\n{Format.channel_name(self.name)}:")
for program in self.programs:
for category in categories:
category = category.lower()
@@ -51,14 +48,12 @@ def print_categories(self, categories: list) -> None:
print()
def print_currently_running(self) -> None:
- print(f"\n{Format.channel_name(self.name)}:")
for program in self.programs:
if program.is_running:
print(program.time_and_title)
print()
def print_times(self, times: list) -> None:
- print(f"\n{Format.channel_name(self.name)}:")
for program in self.programs:
for time in times:
time = Format.user_time(time)
From adacf08fa3f3028532840d3a7ee34aa2b2638f71 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:13:51 +0200
Subject: [PATCH 21/61] Delete method add_program in class Channel and just add
programs in method format_program_info
---
tvguide/tv.py | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 1d5b2a4..71308c0 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -15,11 +15,8 @@ def __init__(self, channel_info: dict, verbose: bool = False) -> None:
def format_program_info(self, channel_info: dict) -> None:
for program_dict in channel_info['programs']:
- self.add_program(program_dict)
-
- def add_program(self, program_info: dict) -> None:
- new_program = Program(program_info, self.verbose)
- self.programs.append(new_program)
+ program = Program(program_dict, self.verbose)
+ self.programs.append(program)
def print_all_programs(self) -> None:
for program in self.programs:
From ba006bd76173492c8c9e5702e833f7d68f4ce75f Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:15:32 +0200
Subject: [PATCH 22/61] Add type hints to properties in classes Channel and
Program
---
tvguide/tv.py | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 71308c0..d5cf903 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -8,7 +8,7 @@
class Channel:
def __init__(self, channel_info: dict, verbose: bool = False) -> None:
self.verbose = verbose
- self.id = channel_info['id']
+ self.id: str = channel_info['id']
self.name = CHANNEL_NUMBER_INDEX[self.id]
self.programs: List[Program] = []
self.format_program_info(channel_info)
@@ -70,15 +70,15 @@ def __init__(self, program_info: dict, verbose: bool = False):
self.format_info()
def format_info(self):
- self.time_start_unix = self.info['start']
- self.time_stop_unix = self.info['stop']
- self.time_start = Format.convert_unix_time(self.time_start_unix, toShow=False)
- self.time_stop = Format.program_time_stop(time_start=self.time_start, time_stop=Format.convert_unix_time(self.time_stop_unix, toShow=False))
- self.time_start_show = Format.convert_unix_time(self.time_start_unix, toShow=True)
- self.time_stop_show = Format.convert_unix_time(self.time_stop_unix, toShow=True)
- self.title = self.info['title']
- self.categories = [cat.lower() for cat in self.info['categories']]
- self.id = self.info['id']
+ self.id: str = self.info['id']
+ self.title: str = self.info['title']
+ self.categories: List[str] = [category.lower() for category in self.info['categories']]
+ self.time_start_unix: int = self.info['start']
+ self.time_stop_unix: int = self.info['stop']
+ self.time_start: int = Format.convert_unix_time(self.time_start_unix, toShow=False)
+ self.time_stop: int = Format.program_time_stop(time_start=self.time_start, time_stop=Format.convert_unix_time(self.time_stop_unix, toShow=False))
+ self.time_start_show: str = Format.convert_unix_time(self.time_start_unix, toShow=True)
+ self.time_stop_show: str = Format.convert_unix_time(self.time_stop_unix, toShow=True)
@property
def time_and_title(self) -> str:
From 60c13eb8d477cdeed6c76b1a80df7c4a16b3b341 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:15:39 +0200
Subject: [PATCH 23/61] Update tvguide.py
---
tvguide/tvguide.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index e1dbf30..4db54ee 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -55,7 +55,7 @@ def print_programs(self) -> None:
channels = self.get_channels(self.input_channels)
for channel in channels:
- print(channel.name)
+ print(channel.name.upper())
def get_channels(self, channel_names: List[str]) -> List[Channel]:
return [channel for channel in self.channels if channel.name in channel_names]
From 3cfcf1e1d1824f61888e595fe2a99236b3371ef8 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:19:36 +0200
Subject: [PATCH 24/61] Update TvGuide.print_programs - Get all channels if
show_all_channels is true else only the input channels
---
tvguide/tvguide.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 4db54ee..4d70747 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -52,7 +52,7 @@ def parse_api_data(self, api_data: dict) -> None:
self.channels.append(channel)
def print_programs(self) -> None:
- channels = self.get_channels(self.input_channels)
+ channels = self.channels if self.show_all_channels else self.get_channels(self.input_channels)
for channel in channels:
print(channel.name.upper())
From 082d2af126f12c6cf989381ca36050c0ac771863 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Mon, 17 Oct 2022 22:20:32 +0200
Subject: [PATCH 25/61] Update TvGuide.print_programs - show all programs if
show_all_programs is true
---
tvguide/tvguide.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 4d70747..210b31a 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -57,6 +57,9 @@ def print_programs(self) -> None:
for channel in channels:
print(channel.name.upper())
+ if self.show_all_programs:
+ channel.print_all_programs()
+
def get_channels(self, channel_names: List[str]) -> List[Channel]:
return [channel for channel in self.channels if channel.name in channel_names]
From 92058f428c259da836656ff9e2d0b10eafd56fb9 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 06:45:01 +0200
Subject: [PATCH 26/61] Rename method format_program_info to
_parse_channel_info in class Channel
---
tvguide/tv.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index d5cf903..4bce602 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -11,9 +11,9 @@ def __init__(self, channel_info: dict, verbose: bool = False) -> None:
self.id: str = channel_info['id']
self.name = CHANNEL_NUMBER_INDEX[self.id]
self.programs: List[Program] = []
- self.format_program_info(channel_info)
+ self._parse_channel_info(channel_info)
- def format_program_info(self, channel_info: dict) -> None:
+ def _parse_channel_info(self, channel_info: dict) -> None:
for program_dict in channel_info['programs']:
program = Program(program_dict, self.verbose)
self.programs.append(program)
From e584a9ebba07e320d4703a76cf2e4134b2a3b9af Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 06:47:45 +0200
Subject: [PATCH 27/61] Update format.py
---
tvguide/format.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvguide/format.py b/tvguide/format.py
index b75d95b..d218d80 100644
--- a/tvguide/format.py
+++ b/tvguide/format.py
@@ -32,7 +32,7 @@ def convert_unix_time(unix_time: int, toShow: bool):
def user_search(search: str) -> str:
search = search.lower()
- spaceSeperator = ConfigManager.get_space_seperator()
+ spaceSeperator = ConfigManager.get_space_seperator()
return search.replace(spaceSeperator, ' ')
From 9486e0558fff30df0a77209b6cd5da659135da92 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 07:05:15 +0200
Subject: [PATCH 28/61] Rename method format_info to _format_info in class
Program
---
tvguide/tv.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 4bce602..ce3cb14 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -67,9 +67,9 @@ class Program:
def __init__(self, program_info: dict, verbose: bool = False):
self.info = program_info
self.verbose = verbose
- self.format_info()
+ self._format_info()
- def format_info(self):
+ def _format_info(self):
self.id: str = self.info['id']
self.title: str = self.info['title']
self.categories: List[str] = [category.lower() for category in self.info['categories']]
From 4e638469482696ed14b59128836658929cd9b2ab Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 07:05:44 +0200
Subject: [PATCH 29/61] Fix type hints
---
tvguide/tv.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index ce3cb14..999a870 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -23,7 +23,7 @@ def print_all_programs(self) -> None:
print(program.start_time_and_title)
print()
- def print_searches(self, search_terms: list) -> None:
+ def print_searches(self, search_terms: List[str]) -> None:
for program in self.programs:
for search in search_terms:
search = Format.user_search(search)
@@ -32,7 +32,7 @@ def print_searches(self, search_terms: list) -> None:
break
print()
- def print_categories(self, categories: list) -> None:
+ def print_categories(self, categories: List[str]) -> None:
for program in self.programs:
for category in categories:
category = category.lower()
@@ -50,7 +50,7 @@ def print_currently_running(self) -> None:
print(program.time_and_title)
print()
- def print_times(self, times: list) -> None:
+ def print_times(self, times: List[str]) -> None:
for program in self.programs:
for time in times:
time = Format.user_time(time)
From 4e4df9fd79b36434244294d4df3be001728da2e6 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 07:06:14 +0200
Subject: [PATCH 30/61] Rename a variable from time to print_time to avoid
shadowing module time
---
tvguide/tv.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 999a870..ea33fd1 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -52,9 +52,9 @@ def print_currently_running(self) -> None:
def print_times(self, times: List[str]) -> None:
for program in self.programs:
- for time in times:
- time = Format.user_time(time)
- if program.is_running_at(time):
+ for print_time in times:
+ print_time = Format.user_time(print_time)
+ if program.is_running_at(print_time):
print(program.time_and_title)
break
print()
From 800ee5fedc4cb0b3be52f269e67fe1eadbff0a00 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 07:06:22 +0200
Subject: [PATCH 31/61] Update tv.py
---
tvguide/tv.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index ea33fd1..6dd5e5b 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -1,5 +1,4 @@
from typing import List
-from datetime import datetime
from .const import CHANNEL_NUMBER_INDEX
from .format import Format, ConfigManager
import time
From cf65530834529077caa394746665999af1235717 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 07:06:37 +0200
Subject: [PATCH 32/61] Simplify method is_running in class Program
---
tvguide/tv.py | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 6dd5e5b..90c4d3e 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -121,10 +121,7 @@ def start_time_and_title_and_category(self) -> str:
def is_running(self) -> bool:
time_now = time.time()
- if time_now == self.time_start_unix or (self.time_start_unix < time_now < self.time_stop_unix):
- return True
-
- return False
+ return self.time_start_unix <= time_now < self.time_stop_unix
def is_running_at(self, time: str):
if self.time_start <= time < self.time_stop:
From dfc5294c8cd9cc97bb64988a3bcc37adc163b1be Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 07:42:07 +0200
Subject: [PATCH 33/61] Add static method read_defaults_config_file to class
ConfigManager
---
tvguide/config.py | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/tvguide/config.py b/tvguide/config.py
index 764c07b..54f7159 100644
--- a/tvguide/config.py
+++ b/tvguide/config.py
@@ -18,9 +18,13 @@ def write(file_name: str, config: ConfigParser) -> None:
with open(file_name, 'w') as default_file:
config.write(default_file)
+ @staticmethod
+ def read_defaults_config_file() -> ConfigParser:
+ return ConfigManager.read(Filemanager.defaults_ini_path)
+
@staticmethod
def get_defaults_user_channels() -> List[str]:
- config = ConfigManager.read(Filemanager.defaults_ini_path)
+ config = ConfigManager.read_defaults_config_file()
defaultChannels = config['DefaultChannels']['channels']
@@ -28,7 +32,7 @@ def get_defaults_user_channels() -> List[str]:
@staticmethod
def change_defaults_user_channels(new_defaults: List[str]) -> None:
- config = ConfigManager.read(Filemanager.defaults_ini_path)
+ config = ConfigManager.read_defaults_config_file()
config['DefaultChannels']['channels'] = ','.join(new_defaults)
@@ -36,13 +40,13 @@ def change_defaults_user_channels(new_defaults: List[str]) -> None:
@staticmethod
def get_space_seperator() -> str:
- config = ConfigManager.read(Filemanager.defaults_ini_path)
+ config = ConfigManager.read_defaults_config_file()
return config['Misc']['spaceSeperator']
@staticmethod
def change_space_seperator(new_space_seperator: str) -> None:
- config = ConfigManager.read(Filemanager.defaults_ini_path)
+ config = ConfigManager.read_defaults_config_file()
config['Misc']['spaceSeperator'] = new_space_seperator
@@ -50,13 +54,13 @@ def change_space_seperator(new_space_seperator: str) -> None:
@staticmethod
def get_justify_length() -> int:
- config = ConfigManager.read(Filemanager.defaults_ini_path)
+ config = ConfigManager.read_defaults_config_file()
return int(config['Misc']['justifyLength'])
@staticmethod
def change_justify_length(new_length: int):
- config = ConfigManager.read(Filemanager.defaults_ini_path)
+ config = ConfigManager.read_defaults_config_file()
config['Misc']['justifyLength'] = new_length
From c5774625026cece64e6c5bf5ed390a9c8d7433d2 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Tue, 18 Oct 2022 07:43:07 +0200
Subject: [PATCH 34/61] Add static method get_timezone to class ConfigManager
---
tvguide/config.py | 6 ++++++
tvguide/defaults.ini | 3 +++
2 files changed, 9 insertions(+)
diff --git a/tvguide/config.py b/tvguide/config.py
index 54f7159..acf8b2d 100644
--- a/tvguide/config.py
+++ b/tvguide/config.py
@@ -65,3 +65,9 @@ def change_justify_length(new_length: int):
config['Misc']['justifyLength'] = new_length
ConfigManager.write(Filemanager.defaults_ini_path, config)
+
+ @staticmethod
+ def get_timezone() -> str:
+ config = ConfigManager.read_defaults_config_file()
+
+ return config["Timezone"]["timezone"]
diff --git a/tvguide/defaults.ini b/tvguide/defaults.ini
index e50c2fd..5d5d6bc 100644
--- a/tvguide/defaults.ini
+++ b/tvguide/defaults.ini
@@ -7,3 +7,6 @@ channels = dr1,tv2
spaceSeperator = *
; Change justify length here or use flag --justify-length
justifyLength = 45
+
+[Timezone]
+timezone = Europe/Copenhagen
From 401cbf6c4f9aafc0744554f38043e6b50b7e970d Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 20:26:59 +0200
Subject: [PATCH 35/61] Move class Channel under class Program in tv.py
---
tvguide/tv.py | 116 +++++++++++++++++++++++++-------------------------
1 file changed, 58 insertions(+), 58 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 90c4d3e..978657d 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -4,64 +4,6 @@
import time
-class Channel:
- def __init__(self, channel_info: dict, verbose: bool = False) -> None:
- self.verbose = verbose
- self.id: str = channel_info['id']
- self.name = CHANNEL_NUMBER_INDEX[self.id]
- self.programs: List[Program] = []
- self._parse_channel_info(channel_info)
-
- def _parse_channel_info(self, channel_info: dict) -> None:
- for program_dict in channel_info['programs']:
- program = Program(program_dict, self.verbose)
- self.programs.append(program)
-
- def print_all_programs(self) -> None:
- for program in self.programs:
- print(program.start_time_and_title)
- print()
-
- def print_searches(self, search_terms: List[str]) -> None:
- for program in self.programs:
- for search in search_terms:
- search = Format.user_search(search)
- if search in program.title.lower():
- print(program.time_and_title)
- break
- print()
-
- def print_categories(self, categories: List[str]) -> None:
- for program in self.programs:
- for category in categories:
- category = category.lower()
- if category in program.categories:
- print(f"{program.time_and_title} ({category.capitalize()})")
- break
- elif program.categories == [] and category in ['nyheder']:
- print(f"{program.time_and_title} ({category.capitalize()})")
- break
- print()
-
- def print_currently_running(self) -> None:
- for program in self.programs:
- if program.is_running:
- print(program.time_and_title)
- print()
-
- def print_times(self, times: List[str]) -> None:
- for program in self.programs:
- for print_time in times:
- print_time = Format.user_time(print_time)
- if program.is_running_at(print_time):
- print(program.time_and_title)
- break
- print()
-
- def __iter__(self):
- return iter(self.programs)
-
-
class Program:
def __init__(self, program_info: dict, verbose: bool = False):
self.info = program_info
@@ -134,3 +76,61 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return f"Program(program_info={self.info})"
+
+
+class Channel:
+ def __init__(self, channel_info: dict, verbose: bool = False) -> None:
+ self.verbose = verbose
+ self.id: str = channel_info['id']
+ self.name = CHANNEL_NUMBER_INDEX[self.id]
+ self.programs: List[Program] = []
+ self._parse_channel_info(channel_info)
+
+ def _parse_channel_info(self, channel_info: dict) -> None:
+ for program_dict in channel_info['programs']:
+ program = Program(program_dict, self.verbose)
+ self.programs.append(program)
+
+ def print_all_programs(self) -> None:
+ for program in self.programs:
+ print(program.start_time_and_title)
+ print()
+
+ def print_searches(self, search_terms: List[str]) -> None:
+ for program in self.programs:
+ for search in search_terms:
+ search = Format.user_search(search)
+ if search in program.title.lower():
+ print(program.time_and_title)
+ break
+ print()
+
+ def print_categories(self, categories: List[str]) -> None:
+ for program in self.programs:
+ for category in categories:
+ category = category.lower()
+ if category in program.categories:
+ print(f"{program.time_and_title} ({category.capitalize()})")
+ break
+ elif program.categories == [] and category in ['nyheder']:
+ print(f"{program.time_and_title} ({category.capitalize()})")
+ break
+ print()
+
+ def print_currently_running(self) -> None:
+ for program in self.programs:
+ if program.is_running:
+ print(program.time_and_title)
+ print()
+
+ def print_times(self, times: List[str]) -> None:
+ for program in self.programs:
+ for print_time in times:
+ print_time = Format.user_time(print_time)
+ if program.is_running_at(print_time):
+ print(program.time_and_title)
+ break
+ print()
+
+ def __iter__(self):
+ return iter(self.programs)
From 8f8292087ae65121692324cfed8d0108428a8d3e Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:24:08 +0200
Subject: [PATCH 36/61] Delete argument --default-space-seperator
And everything that used that argument
---
README.md | 13 -------------
main.py | 4 ----
tvguide/argument.py | 7 -------
tvguide/config.py | 14 --------------
tvguide/format.py | 8 --------
tvguide/tvguide.py | 9 ---------
6 files changed, 55 deletions(-)
diff --git a/README.md b/README.md
index 6dd4f4e..34b3842 100644
--- a/README.md
+++ b/README.md
@@ -45,7 +45,6 @@ This prints the programs (with categories) that is currently running on the defa
- ```-v``` or ```--verbose```
- ```-s [search-term]``` or ```--search [search-term]```
- ```--default-channels [channel]```
-- ```--default-space-seperator [space-seperator]```
- ```--justify-length [int]```
@@ -196,18 +195,6 @@ This changes the default channels to "DR1", "TV2" and "CANAL 9".
-## --default-space-seperator
-
-
-Example:
-```
-python3 main.py --default-space-seperator -
-```
-This changes the default space seperator to the sign "-".
-
-
-
-
## --justify-length
diff --git a/main.py b/main.py
index e5e4766..1dd392a 100644
--- a/main.py
+++ b/main.py
@@ -52,10 +52,6 @@ def change_defaults(args, data: dict):
default_channels_string = ", ".join(args.default_channels).upper()
print(f"Changed default channel(s) to: {default_channels_string}")
- if args.default_space_seperator:
- tv.ConfigManager.change_space_seperator(args.default_space_seperator)
- print(f"Changed space seperator to: {args.default_space_seperator}")
-
if args.justify_length:
tv.ConfigManager.change_justify_length(args.justify_length)
print(f"Changed justify length to: {args.justify_length}")
diff --git a/tvguide/argument.py b/tvguide/argument.py
index 6174b32..901d550 100644
--- a/tvguide/argument.py
+++ b/tvguide/argument.py
@@ -72,13 +72,6 @@ def argparse_setup() -> ArgumentParser.parse_args:
nargs='*'
)
- parser.add_argument(
- '--default-space-seperator',
- dest='default_space_seperator',
- help='change space seperator sign',
- type=str
- )
-
parser.add_argument(
'--justify-length',
dest='justify_length',
diff --git a/tvguide/config.py b/tvguide/config.py
index acf8b2d..bd39c28 100644
--- a/tvguide/config.py
+++ b/tvguide/config.py
@@ -38,20 +38,6 @@ def change_defaults_user_channels(new_defaults: List[str]) -> None:
ConfigManager.write(Filemanager.defaults_ini_path, config)
- @staticmethod
- def get_space_seperator() -> str:
- config = ConfigManager.read_defaults_config_file()
-
- return config['Misc']['spaceSeperator']
-
- @staticmethod
- def change_space_seperator(new_space_seperator: str) -> None:
- config = ConfigManager.read_defaults_config_file()
-
- config['Misc']['spaceSeperator'] = new_space_seperator
-
- ConfigManager.write(Filemanager.defaults_ini_path, config)
-
@staticmethod
def get_justify_length() -> int:
config = ConfigManager.read_defaults_config_file()
diff --git a/tvguide/format.py b/tvguide/format.py
index d218d80..ac64081 100644
--- a/tvguide/format.py
+++ b/tvguide/format.py
@@ -28,14 +28,6 @@ def convert_unix_time(unix_time: int, toShow: bool):
else:
return int(time.strftime('%H%M'))
- @staticmethod
- def user_search(search: str) -> str:
- search = search.lower()
-
- spaceSeperator = ConfigManager.get_space_seperator()
-
- return search.replace(spaceSeperator, ' ')
-
@staticmethod
def program_time_stop(time_start: int, time_stop: int) -> int:
if time_start > time_stop:
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 210b31a..de3f383 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -29,9 +29,6 @@ def parse_arguments(self, args: argparse.Namespace) -> None:
if args.default_channels:
self._change_default_channels(args.default_channels)
- if args.default_space_seperator:
- self._change_default_space_seperator(args.default_space_seperator)
-
if args.justify_length:
self._change_default_justify_length(args.justify_length)
@@ -66,17 +63,11 @@ def get_channels(self, channel_names: List[str]) -> List[Channel]:
def _change_default_channels(self, channels: List[str]) -> None:
ConfigManager.change_defaults_user_channels(channels)
- def _change_default_space_seperator(self, space_seperator: str) -> None:
- ConfigManager.change_space_seperator(space_seperator)
-
def _change_default_justify_length(self, justify_length: int) -> None:
ConfigManager.change_justify_length(justify_length)
def get_default_channels(self) -> List[str]:
return ConfigManager.get_defaults_user_channels()
- def get_default_space_seperator(self) -> str:
- return ConfigManager.get_space_seperator()
-
def get_default_justify_length(self) -> int:
return ConfigManager.get_justify_length()
From 4cb5d66af5d27913183ec13d6dc3848ebda23f62 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:25:43 +0200
Subject: [PATCH 37/61] Update class Channel - create "_get..." methods to
simplify "print_..." methods
---
tvguide/tv.py | 65 +++++++++++++++++++++++++++++----------------------
1 file changed, 37 insertions(+), 28 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 978657d..dbf0a5c 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -1,4 +1,4 @@
-from typing import List
+from typing import Iterator, List
from .const import CHANNEL_NUMBER_INDEX
from .format import Format, ConfigManager
import time
@@ -94,43 +94,52 @@ def _parse_channel_info(self, channel_info: dict) -> None:
def print_all_programs(self) -> None:
for program in self.programs:
print(program.start_time_and_title)
- print()
def print_searches(self, search_terms: List[str]) -> None:
- for program in self.programs:
- for search in search_terms:
- search = Format.user_search(search)
- if search in program.title.lower():
- print(program.time_and_title)
- break
- print()
+ for search_term in search_terms:
+ programs_with_search_term = self._get_programs_with_search_term(search_term)
+ for program in programs_with_search_term:
+ print(program.time_and_title)
def print_categories(self, categories: List[str]) -> None:
- for program in self.programs:
- for category in categories:
- category = category.lower()
- if category in program.categories:
- print(f"{program.time_and_title} ({category.capitalize()})")
- break
- elif program.categories == [] and category in ['nyheder']:
- print(f"{program.time_and_title} ({category.capitalize()})")
- break
- print()
+ for category in categories:
+ programs_with_category = self._get_programs_with_category(category)
+ for program in programs_with_category:
+ print(f"{program.time_and_title} ({category.capitalize()})")
def print_currently_running(self) -> None:
+ running_program = self._get_currently_running_program()
+ print(running_program.time_and_title)
+
+ def print_times(self, times: List[str]) -> None:
+ for program in self._get_programs_with_show_times(times):
+ print(program.time_and_title)
+
+ def _get_currently_running_program(self) -> Program:
for program in self.programs:
if program.is_running:
- print(program.time_and_title)
- print()
+ return program
- def print_times(self, times: List[str]) -> None:
+ def _get_programs_with_category(self, category: str) -> List[Program]:
+ programs_with_category: List[Program] = []
+ for program in self.programs:
+ if category.lower() in program.categories or program.categories == [] and category in ["nyheder"]:
+ programs_with_category.append(program)
+ return programs_with_category
+
+ def _get_programs_with_search_term(self, search_term: str) -> List[Program]:
+ programs_with_search_term: List[Program] = []
+ for program in self.programs:
+ if search_term.lower() in program.title.lower():
+ programs_with_search_term.append(program)
+ return programs_with_search_term
+
+ def _get_programs_with_show_times(self, show_times: List[str]) -> Iterator[Program]:
for program in self.programs:
- for print_time in times:
- print_time = Format.user_time(print_time)
- if program.is_running_at(print_time):
- print(program.time_and_title)
- break
- print()
+ for show_time in show_times:
+ time_int = Format.user_time(show_time)
+ if program.is_running_at(time_int):
+ yield program
def __iter__(self):
return iter(self.programs)
From aaf36ed701f254a6291b6fd76beb5cd55cee4161 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:26:02 +0200
Subject: [PATCH 38/61] Simplify method "is_running_at" in class Program
---
tvguide/tv.py | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index dbf0a5c..1ca1af9 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -62,14 +62,10 @@ def start_time_and_title_and_category(self) -> str:
@property
def is_running(self) -> bool:
time_now = time.time()
-
return self.time_start_unix <= time_now < self.time_stop_unix
- def is_running_at(self, time: str):
- if self.time_start <= time < self.time_stop:
- return True
-
- return False
+ def is_running_at(self, time: int) -> bool:
+ return self.time_start <= time < self.time_stop
def __str__(self) -> str:
return self.time_and_title
From 97d37a63aad78c2f3c02b3c343c3743a8b5a9264 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:27:24 +0200
Subject: [PATCH 39/61] Update class TvGuide - add properties to keep track of
what to print and add if-statements in methods "parse_arguments" and
"print_programs"
---
tvguide/tvguide.py | 47 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 39 insertions(+), 8 deletions(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index de3f383..a9b9707 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -12,11 +12,13 @@ def __init__(self) -> None:
self.show_now = False
self.show_all_channels = False
self.show_all_programs = False
- self.show_time = False
- self.input_time = None
- self.search = False
+ self.search_times = False
+ self.search_categories = False
+ self.search_names = False
+ self.input_times: List[str] = []
self.input_channels: List[str] = []
- self.search_terms: List[str] = []
+ self.input_categories: List[str] = []
+ self.input_search_terms: List[str] = []
self.channels: List[Channel] = []
def parse_arguments(self, args: argparse.Namespace) -> None:
@@ -24,7 +26,6 @@ def parse_arguments(self, args: argparse.Namespace) -> None:
self.show_now = args.now
self.relative_date = args.day
self.show_all_programs = args.all
- self.search = args.search
if args.default_channels:
self._change_default_channels(args.default_channels)
@@ -32,9 +33,17 @@ def parse_arguments(self, args: argparse.Namespace) -> None:
if args.justify_length:
self._change_default_justify_length(args.justify_length)
+ if args.search:
+ self.search_names = True
+ self.input_search_terms = args.search
+
+ if args.category:
+ self.search_categories = True
+ self.input_categories = args.category
+
if args.time:
- self.show_time = True
- self.input_time = args.time
+ self.search_times = True
+ self.input_times = args.time
if not args.channels:
self.input_channels = self.get_default_channels()
@@ -52,10 +61,32 @@ def print_programs(self) -> None:
channels = self.channels if self.show_all_channels else self.get_channels(self.input_channels)
for channel in channels:
- print(channel.name.upper())
+ print(f"\n{channel.name.upper()}")
if self.show_all_programs:
+ print("----- ALL -----")
channel.print_all_programs()
+ print()
+
+ if self.search_categories:
+ print("----- CATEGORY -----")
+ channel.print_categories(self.input_categories)
+ print()
+
+ if self.search_times:
+ print("----- TIMES -----")
+ channel.print_times(self.input_times)
+ print()
+
+ if self.search_names:
+ print("----- SEARCH -----")
+ channel.print_searches(self.input_search_terms)
+ print()
+
+ if self.show_now:
+ print("----- NOW -----")
+ channel.print_currently_running()
+ print()
def get_channels(self, channel_names: List[str]) -> List[Channel]:
return [channel for channel in self.channels if channel.name in channel_names]
From e1168805bfb093765dfdece1fdb53bbc43118202 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:38:41 +0200
Subject: [PATCH 40/61] Use cache when reading config file
---
tvguide/config.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tvguide/config.py b/tvguide/config.py
index bd39c28..54f2a68 100644
--- a/tvguide/config.py
+++ b/tvguide/config.py
@@ -1,5 +1,6 @@
from typing import List
from configparser import ConfigParser
+from functools import cache
from .filemanager import Filemanager
@@ -19,6 +20,7 @@ def write(file_name: str, config: ConfigParser) -> None:
config.write(default_file)
@staticmethod
+ @cache
def read_defaults_config_file() -> ConfigParser:
return ConfigManager.read(Filemanager.defaults_ini_path)
From e0c02127ffbcc0448eeacacd98e251d7c688e072 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:39:02 +0200
Subject: [PATCH 41/61] Update README - requires python 3.9+
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index 34b3842..68ac8e3 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,10 @@ A program that gives the user a list over what comes in tv*.
+Requires ```python3.9+```
+
+
+
# How to use
An example on how to use this program:
From c99e5b3fb078fb913a0f0131ff5792a35423292c Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:46:31 +0200
Subject: [PATCH 42/61] Reorder imports and replace relative imports with
absolute imports
---
tvguide/api.py | 7 ++++---
tvguide/config.py | 2 +-
tvguide/format.py | 1 -
tvguide/tv.py | 5 +++--
tvguide/tvguide.py | 2 +-
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/tvguide/api.py b/tvguide/api.py
index 5ebd41b..462934a 100644
--- a/tvguide/api.py
+++ b/tvguide/api.py
@@ -1,8 +1,9 @@
import requests
import requests_cache
-from .const import API_LINK, REQUEST_HEADER, REQUEST_COOKIES
-from .format import Format
-from .tv import Channel
+
+from tvguide.const import API_LINK, REQUEST_HEADER, REQUEST_COOKIES
+from tvguide.format import Format
+from tvguide.tv import Channel
requests_cache.install_cache(cache_name="api_cache", expire_after=120, backend="filesystem")
diff --git a/tvguide/config.py b/tvguide/config.py
index 54f2a68..54cf845 100644
--- a/tvguide/config.py
+++ b/tvguide/config.py
@@ -2,7 +2,7 @@
from configparser import ConfigParser
from functools import cache
-from .filemanager import Filemanager
+from tvguide.filemanager import Filemanager
class ConfigManager:
diff --git a/tvguide/format.py b/tvguide/format.py
index ac64081..ecd6bc8 100644
--- a/tvguide/format.py
+++ b/tvguide/format.py
@@ -1,5 +1,4 @@
from datetime import datetime, timedelta, timezone
-from .config import ConfigManager
import pytz
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 1ca1af9..fb97a25 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -1,8 +1,9 @@
from typing import Iterator, List
-from .const import CHANNEL_NUMBER_INDEX
-from .format import Format, ConfigManager
import time
+from tvguide.const import CHANNEL_NUMBER_INDEX
+from tvguide.format import Format, ConfigManager
+
class Program:
def __init__(self, program_info: dict, verbose: bool = False):
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index a9b9707..593f0a6 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -1,7 +1,7 @@
from typing import List
import argparse
-from tvguide.config import ConfigManager
+from tvguide.config import ConfigManager
from tvguide.tv import Channel
From b620e8486450e40a47de49b14c90cd68a17d7548 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:46:55 +0200
Subject: [PATCH 43/61] Update LICENCE to 2022
---
LICENSE | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LICENSE b/LICENSE
index 6fd18d8..d36798c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2021 Crinibus
+Copyright (c) 2022 Crinibus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
From 67e41d3589d5e0393a3b2748e10dc4ca81dae729 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 23:08:00 +0200
Subject: [PATCH 44/61] Fix import
---
tvguide/tv.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index fb97a25..6deaeb2 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -2,8 +2,8 @@
import time
from tvguide.const import CHANNEL_NUMBER_INDEX
-from tvguide.format import Format, ConfigManager
-
+from tvguide.format import Format
+from tvguide.config import ConfigManager
class Program:
def __init__(self, program_info: dict, verbose: bool = False):
From 35d8b2fa0c1907e41bd6f3a7fbdfe7e4f966e1a3 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Thu, 20 Oct 2022 23:11:45 +0200
Subject: [PATCH 45/61] Update tv.py
---
tvguide/tv.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index 6deaeb2..e1af731 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -5,6 +5,7 @@
from tvguide.format import Format
from tvguide.config import ConfigManager
+
class Program:
def __init__(self, program_info: dict, verbose: bool = False):
self.info = program_info
From 669a894037a694107b3435b1fc8a9f670dda826e Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 00:20:43 +0200
Subject: [PATCH 46/61] Add print when currently running program is found
---
tvguide/tv.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index e1af731..f80e10b 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -107,6 +107,14 @@ def print_categories(self, categories: List[str]) -> None:
def print_currently_running(self) -> None:
running_program = self._get_currently_running_program()
+
+ if not running_program:
+ print(
+ "*Could not find a running program"
+ " - if the time right now is after midnight before 6 am, try getting programs for yesterday*"
+ )
+ return
+
print(running_program.time_and_title)
def print_times(self, times: List[str]) -> None:
From 410eff95da79e1d6d209df11ea8a62a8a88e9587 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 00:21:58 +0200
Subject: [PATCH 47/61] Split a line to two lines
---
tvguide/tv.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index f80e10b..b88b542 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -19,7 +19,8 @@ def _format_info(self):
self.time_start_unix: int = self.info['start']
self.time_stop_unix: int = self.info['stop']
self.time_start: int = Format.convert_unix_time(self.time_start_unix, toShow=False)
- self.time_stop: int = Format.program_time_stop(time_start=self.time_start, time_stop=Format.convert_unix_time(self.time_stop_unix, toShow=False))
+ temp_time_stop = Format.convert_unix_time(self.time_stop_unix, toShow=False)
+ self.time_stop: int = Format.program_time_stop(time_start=self.time_start, time_stop=temp_time_stop)
self.time_start_show: str = Format.convert_unix_time(self.time_start_unix, toShow=True)
self.time_stop_show: str = Format.convert_unix_time(self.time_stop_unix, toShow=True)
From 7de08ef45fdc82c674e01c837173afa137cbd08a Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 00:22:10 +0200
Subject: [PATCH 48/61] Format with black
---
tvguide/tv.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tvguide/tv.py b/tvguide/tv.py
index b88b542..e1ee1a5 100644
--- a/tvguide/tv.py
+++ b/tvguide/tv.py
@@ -13,11 +13,11 @@ def __init__(self, program_info: dict, verbose: bool = False):
self._format_info()
def _format_info(self):
- self.id: str = self.info['id']
- self.title: str = self.info['title']
- self.categories: List[str] = [category.lower() for category in self.info['categories']]
- self.time_start_unix: int = self.info['start']
- self.time_stop_unix: int = self.info['stop']
+ self.id: str = self.info["id"]
+ self.title: str = self.info["title"]
+ self.categories: List[str] = [category.lower() for category in self.info["categories"]]
+ self.time_start_unix: int = self.info["start"]
+ self.time_stop_unix: int = self.info["stop"]
self.time_start: int = Format.convert_unix_time(self.time_start_unix, toShow=False)
temp_time_stop = Format.convert_unix_time(self.time_stop_unix, toShow=False)
self.time_stop: int = Format.program_time_stop(time_start=self.time_start, time_stop=temp_time_stop)
@@ -80,13 +80,13 @@ def __repr__(self) -> str:
class Channel:
def __init__(self, channel_info: dict, verbose: bool = False) -> None:
self.verbose = verbose
- self.id: str = channel_info['id']
+ self.id: str = channel_info["id"]
self.name = CHANNEL_NUMBER_INDEX[self.id]
self.programs: List[Program] = []
self._parse_channel_info(channel_info)
def _parse_channel_info(self, channel_info: dict) -> None:
- for program_dict in channel_info['programs']:
+ for program_dict in channel_info["programs"]:
program = Program(program_dict, self.verbose)
self.programs.append(program)
From 960bffb43260ec39b8120139410e49043983b5f4 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 00:23:23 +0200
Subject: [PATCH 49/61] Add config files for flake8 and black
---
.flake8 | 5 +++++
pyproject.toml | 2 ++
2 files changed, 7 insertions(+)
create mode 100644 .flake8
create mode 100644 pyproject.toml
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..01a4ef3
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,5 @@
+[flake8]
+max-complexity = 10
+max-line-length = 127
+exclude = .git,__pycache__
+per-file-ignores = __init__.py:F401
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..dcff8a7
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,2 @@
+[tool.black]
+line-length = 127
From e50d968ffdd8ebfe29133dea6ed6bc240eabe657 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 00:24:37 +0200
Subject: [PATCH 50/61] Format with black
---
tvguide/argument.py | 79 +++++++++++++-----------------------------
tvguide/config.py | 12 +++----
tvguide/const.py | 4 ++-
tvguide/filemanager.py | 1 +
tvguide/format.py | 8 ++---
5 files changed, 38 insertions(+), 66 deletions(-)
diff --git a/tvguide/argument.py b/tvguide/argument.py
index 901d550..6a42066 100644
--- a/tvguide/argument.py
+++ b/tvguide/argument.py
@@ -6,87 +6,56 @@ def argparse_setup() -> ArgumentParser.parse_args:
parser = ArgumentParser()
parser.add_argument(
- '-c',
- '--channel',
- dest='channels',
- help='the channel with the user want to see programs from',
+ "-c",
+ "--channel",
+ dest="channels",
+ help="the channel with the user want to see programs from",
nargs="*",
action="extend",
- type=str
+ type=str,
)
parser.add_argument(
- '-t',
- '--time',
- dest='time',
- metavar='hh:mm',
+ "-t",
+ "--time",
+ dest="time",
+ metavar="hh:mm",
help='the time the program starts. E.g. "20:00". Format is: "hh:mm"',
nargs="*",
action="extend",
- type=str
+ type=str,
)
- parser.add_argument(
- '-a',
- '--all',
- help='show all programs for the chosen channel(s)',
- action='store_true'
- )
+ parser.add_argument("-a", "--all", help="show all programs for the chosen channel(s)", action="store_true")
parser.add_argument(
- '-d',
- '--day',
- help='the relative day the programs is running, default today (0)',
+ "-d",
+ "--day",
+ help="the relative day the programs is running, default today (0)",
choices=[-1, 0, 1, 2, 3, 4, 5, 6],
type=int,
- default=0
+ default=0,
)
parser.add_argument(
- '--category',
- dest='category',
- help='only show the programs with the chosen category(s)',
+ "--category",
+ dest="category",
+ help="only show the programs with the chosen category(s)",
nargs="*",
action="extend",
- type=str
+ type=str,
)
- parser.add_argument(
- '-n',
- '--now',
- help='only show the program(s) that is currently',
- action='store_true'
- )
+ parser.add_argument("-n", "--now", help="only show the program(s) that is currently", action="store_true")
- parser.add_argument(
- '-v',
- '--verbose',
- help='show categories when using --all and --time',
- action='store_true'
- )
+ parser.add_argument("-v", "--verbose", help="show categories when using --all and --time", action="store_true")
parser.add_argument(
- '--default-channels',
- dest='default_channels',
- help='change default channels to the chosen channel(s)',
- nargs='*'
+ "--default-channels", dest="default_channels", help="change default channels to the chosen channel(s)", nargs="*"
)
- parser.add_argument(
- '--justify-length',
- dest='justify_length',
- help='change justify length',
- type=str
- )
+ parser.add_argument("--justify-length", dest="justify_length", help="change justify length", type=str)
- parser.add_argument(
- '-s',
- '--search',
- dest='search',
- help='search for programs',
- nargs="*",
- action="extend",
- type=str
- )
+ parser.add_argument("-s", "--search", dest="search", help="search for programs", nargs="*", action="extend", type=str)
return parser.parse_args()
diff --git a/tvguide/config.py b/tvguide/config.py
index 54cf845..afdbc75 100644
--- a/tvguide/config.py
+++ b/tvguide/config.py
@@ -16,7 +16,7 @@ def read(file_name: str) -> ConfigParser:
@staticmethod
def write(file_name: str, config: ConfigParser) -> None:
"""Write user settings in {file_name}.ini"""
- with open(file_name, 'w') as default_file:
+ with open(file_name, "w") as default_file:
config.write(default_file)
@staticmethod
@@ -28,15 +28,15 @@ def read_defaults_config_file() -> ConfigParser:
def get_defaults_user_channels() -> List[str]:
config = ConfigManager.read_defaults_config_file()
- defaultChannels = config['DefaultChannels']['channels']
+ defaultChannels = config["DefaultChannels"]["channels"]
- return defaultChannels.split(',')
+ return defaultChannels.split(",")
@staticmethod
def change_defaults_user_channels(new_defaults: List[str]) -> None:
config = ConfigManager.read_defaults_config_file()
- config['DefaultChannels']['channels'] = ','.join(new_defaults)
+ config["DefaultChannels"]["channels"] = ",".join(new_defaults)
ConfigManager.write(Filemanager.defaults_ini_path, config)
@@ -44,13 +44,13 @@ def change_defaults_user_channels(new_defaults: List[str]) -> None:
def get_justify_length() -> int:
config = ConfigManager.read_defaults_config_file()
- return int(config['Misc']['justifyLength'])
+ return int(config["Misc"]["justifyLength"])
@staticmethod
def change_justify_length(new_length: int):
config = ConfigManager.read_defaults_config_file()
- config['Misc']['justifyLength'] = new_length
+ config["Misc"]["justifyLength"] = new_length
ConfigManager.write(Filemanager.defaults_ini_path, config)
diff --git a/tvguide/const.py b/tvguide/const.py
index 0dc8f19..0ec55c7 100644
--- a/tvguide/const.py
+++ b/tvguide/const.py
@@ -1,6 +1,8 @@
API_LINK = "https://tvtid-api.api.tv2.dk/api/tvtid/v1/epg/dayviews/{date}?ch=1&ch=2&ch=3&ch=4&ch=5&ch=6&ch=7&ch=8&ch=9&ch=10&ch=10&ch=11&ch=12&ch=14&ch=15&ch=19&ch=20&ch=25&ch=26&ch=31&ch=37&ch=39&ch=70&ch=71&ch=74&ch=77&ch=93&ch=94&ch=111&ch=116&ch=117&ch=118&ch=129&ch=130&ch=133&ch=135&ch=136&ch=142&ch=147&ch=153&ch=156&ch=157&ch=161&ch=162&ch=163&ch=164&ch=165&ch=174&ch=181&ch=185&ch=188&ch=191&ch=201&ch=215&ch=218&ch=219&ch=221&ch=240&ch=248&ch=570&ch=687&ch=689&ch=10061&ch=10066&ch=10070&ch=10093&ch=10104&ch=10111&ch=10145&ch=10153&ch=10159&ch=10262&ch=10341&ch=10435&ch=10455&ch=10510&ch=10511&ch=10621&ch=11572&ch=11610&ch=11611&ch=11612&ch=11613&ch=11614&ch=11615&ch=11616&ch=11617&ch=12034&ch=12396&ch=12566&ch=12697&ch=12948&ch=15032&ch=15049&ch=15129&ch=2147483561&ch=2147483566&ch=2147483567&ch=2147483568"
-REQUEST_HEADER = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"}
+REQUEST_HEADER = {
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
+}
REQUEST_COOKIES = {"cookies_are": "working"}
diff --git a/tvguide/filemanager.py b/tvguide/filemanager.py
index db00b2a..4581323 100644
--- a/tvguide/filemanager.py
+++ b/tvguide/filemanager.py
@@ -1,5 +1,6 @@
import pathlib
+
class Filemanager:
# root path of this repository
root_path = pathlib.Path(__file__).parent.parent.absolute()
diff --git a/tvguide/format.py b/tvguide/format.py
index ecd6bc8..630b219 100644
--- a/tvguide/format.py
+++ b/tvguide/format.py
@@ -12,20 +12,20 @@ def get_specified_date(relative_date: int) -> str:
"""Convert relative date to real date, so that if argument 'relative_date' is 1, it get converted to tomorrow"""
date = datetime.today()
date += timedelta(days=relative_date)
- return date.strftime('%Y-%m-%d')
+ return date.strftime("%Y-%m-%d")
@staticmethod
def convert_unix_time(unix_time: int, toShow: bool):
"""Convert UNIX times to hour and minutes, e.g.: 1604692800 -> 2000 or 20:00\n
- UNIX time is converted to timezone: Europe/Copenhagen"""
+ UNIX time is converted to timezone: Europe/Copenhagen"""
copenhagen_timezone = pytz.timezone("Europe/Copenhagen")
time = pytz.utc.localize(datetime.utcfromtimestamp(unix_time)).astimezone(copenhagen_timezone)
if toShow:
- return time.strftime('%H:%M')
+ return time.strftime("%H:%M")
else:
- return int(time.strftime('%H%M'))
+ return int(time.strftime("%H%M"))
@staticmethod
def program_time_stop(time_start: int, time_stop: int) -> int:
From b5f3ca2ceb9b08068e6232969dc60954088ae466 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 00:32:50 +0200
Subject: [PATCH 51/61] Update Chrome version in REQUEST_HEADER
---
tvguide/const.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tvguide/const.py b/tvguide/const.py
index 0ec55c7..67701d7 100644
--- a/tvguide/const.py
+++ b/tvguide/const.py
@@ -1,7 +1,7 @@
API_LINK = "https://tvtid-api.api.tv2.dk/api/tvtid/v1/epg/dayviews/{date}?ch=1&ch=2&ch=3&ch=4&ch=5&ch=6&ch=7&ch=8&ch=9&ch=10&ch=10&ch=11&ch=12&ch=14&ch=15&ch=19&ch=20&ch=25&ch=26&ch=31&ch=37&ch=39&ch=70&ch=71&ch=74&ch=77&ch=93&ch=94&ch=111&ch=116&ch=117&ch=118&ch=129&ch=130&ch=133&ch=135&ch=136&ch=142&ch=147&ch=153&ch=156&ch=157&ch=161&ch=162&ch=163&ch=164&ch=165&ch=174&ch=181&ch=185&ch=188&ch=191&ch=201&ch=215&ch=218&ch=219&ch=221&ch=240&ch=248&ch=570&ch=687&ch=689&ch=10061&ch=10066&ch=10070&ch=10093&ch=10104&ch=10111&ch=10145&ch=10153&ch=10159&ch=10262&ch=10341&ch=10435&ch=10455&ch=10510&ch=10511&ch=10621&ch=11572&ch=11610&ch=11611&ch=11612&ch=11613&ch=11614&ch=11615&ch=11616&ch=11617&ch=12034&ch=12396&ch=12566&ch=12697&ch=12948&ch=15032&ch=15049&ch=15129&ch=2147483561&ch=2147483566&ch=2147483567&ch=2147483568"
REQUEST_HEADER = {
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
}
REQUEST_COOKIES = {"cookies_are": "working"}
From 6b7f0d4c9f294e90f6b7960c820eeb10beff4b12 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 20:56:51 +0200
Subject: [PATCH 52/61] Add print when using default channels
Print the default channels
---
tvguide/tvguide.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 593f0a6..14f0ea0 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -47,6 +47,8 @@ def parse_arguments(self, args: argparse.Namespace) -> None:
if not args.channels:
self.input_channels = self.get_default_channels()
+ default_channels_string = ", ".join(self.input_channels).upper()
+ print(f"No channel(s) chosen - using default channels: {default_channels_string}")
elif "all" in args.channels:
self.show_all_channels = True
else:
From 11dac393bc66177470872354c0d21282a05b9856 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 20:58:25 +0200
Subject: [PATCH 53/61] Change prints before showing the programs
Add what the user has inputted, e.g. categories, times and search terms
---
tvguide/tvguide.py | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 14f0ea0..5d95a64 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -66,27 +66,30 @@ def print_programs(self) -> None:
print(f"\n{channel.name.upper()}")
if self.show_all_programs:
- print("----- ALL -----")
+ print("----- ALL PROGRAMS -----")
channel.print_all_programs()
print()
if self.search_categories:
- print("----- CATEGORY -----")
+ input_categories_string = ", ".join(self.input_categories)
+ print(f"----- PROGRAMS WITH CATEGORY(s): {input_categories_string} -----")
channel.print_categories(self.input_categories)
print()
if self.search_times:
- print("----- TIMES -----")
+ input_times_string = ", ".join(self.input_times)
+ print(f"----- RUNNING AT TIME(s): {input_times_string} -----")
channel.print_times(self.input_times)
print()
if self.search_names:
- print("----- SEARCH -----")
+ input_search_terms_string = ", ".join(self.input_search_terms)
+ print(f"----- SEARCH TERM(s): {input_search_terms_string} -----")
channel.print_searches(self.input_search_terms)
print()
if self.show_now:
- print("----- NOW -----")
+ print("----- CURRENTLY RUNNING -----")
channel.print_currently_running()
print()
From 8b8ab24420123d291af98a1d34f6206a8e1c8039 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Sun, 23 Oct 2022 21:55:59 +0200
Subject: [PATCH 54/61] Fix print statements in main.py - delete end=""
---
main.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/main.py b/main.py
index 1dd392a..6d88ade 100644
--- a/main.py
+++ b/main.py
@@ -8,7 +8,7 @@
def print_currently_running(data_source: dict, user_channels: list) -> None:
channels_string = ", ".join(user_channels).upper()
- print(f"\n----- Showing currently running programs for: {channels_string} -----", end="")
+ print(f"\n----- Showing currently running programs for: {channels_string} -----")
for channel in user_channels:
data_source[channel].print_currently_running()
@@ -17,7 +17,7 @@ def print_program_times(data_source: dict, user_channels: list, user_times: list
channels_string = ", ".join(user_channels).upper()
user_times_string = ", ".join(user_times)
- print(f"\n----- Showing programs that is running at: {user_times_string} for: {channels_string} -----", end="")
+ print(f"\n----- Showing programs that is running at: {user_times_string} for: {channels_string} -----")
for channel in user_channels:
data_source[channel].print_times(user_times)
@@ -25,7 +25,7 @@ def print_program_times(data_source: dict, user_channels: list, user_times: list
def print_program_categories(data_source: dict, user_channels: list, user_categories: list) -> None:
user_categories_string = ", ".join(user_categories)
- print(f"\n----- Searching for categories: {user_categories_string} -----", end="")
+ print(f"\n----- Searching for categories: {user_categories_string} -----")
for channel in user_channels:
data_source[channel].print_categories(user_categories)
@@ -33,7 +33,7 @@ def print_program_categories(data_source: dict, user_channels: list, user_catego
def print_program_searches(data_source: dict, user_channels: list, user_searches: list) -> None:
user_search_string = tv.Format.user_search(", ".join(user_searches))
- print(f"\n----- Searching for keywords: {user_search_string} -----", end="")
+ print(f"\n----- Searching for keywords: {user_search_string} -----")
for channel in user_channels:
data_source[channel].print_searches(user_searches)
@@ -41,7 +41,7 @@ def print_program_searches(data_source: dict, user_channels: list, user_searches
def print_program_all(data_source: dict, user_channels: list) -> None:
user_channels_string = ", ".join(user_channels).upper()
- print(f"\n----- Showing all programs for: {user_channels_string} -----", end="")
+ print(f"\n----- Showing all programs for: {user_channels_string} -----")
for channel in user_channels:
data_source[channel].print_all_programs()
From 834be880875e94fe8996b42c9d1387eb829868fb Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Fri, 28 Oct 2022 23:00:23 +0200
Subject: [PATCH 55/61] Add try catch around main function call
---
main_v2.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/main_v2.py b/main_v2.py
index 9f8f6ac..39e1144 100644
--- a/main_v2.py
+++ b/main_v2.py
@@ -16,4 +16,7 @@ def main():
if __name__ == "__main__":
- main()
+ try:
+ main()
+ except KeyboardInterrupt:
+ print("Stopped by user")
From 2c4f8c06538c011555ad8f72914e68ee3db7f226 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Fri, 28 Oct 2022 23:03:07 +0200
Subject: [PATCH 56/61] Delete main.py
---
main.py | 102 --------------------------------------------------------
1 file changed, 102 deletions(-)
delete mode 100644 main.py
diff --git a/main.py b/main.py
deleted file mode 100644
index 6d88ade..0000000
--- a/main.py
+++ /dev/null
@@ -1,102 +0,0 @@
-# from format import Format
-# from argument import argparse_setup
-# from API import API
-# from Config import Config
-import tvguide as tv
-
-
-def print_currently_running(data_source: dict, user_channels: list) -> None:
- channels_string = ", ".join(user_channels).upper()
-
- print(f"\n----- Showing currently running programs for: {channels_string} -----")
- for channel in user_channels:
- data_source[channel].print_currently_running()
-
-
-def print_program_times(data_source: dict, user_channels: list, user_times: list) -> None:
- channels_string = ", ".join(user_channels).upper()
- user_times_string = ", ".join(user_times)
-
- print(f"\n----- Showing programs that is running at: {user_times_string} for: {channels_string} -----")
- for channel in user_channels:
- data_source[channel].print_times(user_times)
-
-
-def print_program_categories(data_source: dict, user_channels: list, user_categories: list) -> None:
- user_categories_string = ", ".join(user_categories)
-
- print(f"\n----- Searching for categories: {user_categories_string} -----")
- for channel in user_channels:
- data_source[channel].print_categories(user_categories)
-
-
-def print_program_searches(data_source: dict, user_channels: list, user_searches: list) -> None:
- user_search_string = tv.Format.user_search(", ".join(user_searches))
-
- print(f"\n----- Searching for keywords: {user_search_string} -----")
- for channel in user_channels:
- data_source[channel].print_searches(user_searches)
-
-
-def print_program_all(data_source: dict, user_channels: list) -> None:
- user_channels_string = ", ".join(user_channels).upper()
-
- print(f"\n----- Showing all programs for: {user_channels_string} -----")
- for channel in user_channels:
- data_source[channel].print_all_programs()
-
-
-def change_defaults(args, data: dict):
- if args.default_channels:
- tv.ConfigManager.change_defaults_user_channels(args.default_channels)
- default_channels_string = ", ".join(args.default_channels).upper()
- print(f"Changed default channel(s) to: {default_channels_string}")
-
- if args.justify_length:
- tv.ConfigManager.change_justify_length(args.justify_length)
- print(f"Changed justify length to: {args.justify_length}")
-
- if not args.channels:
- args.channels = tv.ConfigManager.get_defaults_user_channels()
- default_channels_string = ", ".join(args.channels).upper()
- print(f"No channel(s) chosen: using default channels ({default_channels_string})")
- elif args.channels[0].lower() == "all":
- args.channels = [channel for channel in data.keys()]
-
-
-def print_programs(args, data):
- if args.now:
- print_currently_running(data, args.channels)
-
- if args.time:
- print_program_times(data, args.channels, args.time)
-
- if args.category:
- print_program_categories(data, args.channels, args.category)
-
- if args.search:
- print_program_searches(data, args.channels, args.search)
-
- if args.all:
- print_program_all(data, args.channels)
-
-
-def main():
- args = tv.argparse_setup()
-
- api_data = tv.ApiManager.get_data(args.day)
-
- my_data = tv.ApiManager.format_data(api_data, args.verbose)
-
- change_defaults(args, my_data)
-
- print_programs(args, my_data)
-
-
-if __name__ == "__main__":
- try:
- main()
- except KeyError:
- print("Check channel name or this scraper can't use this channel")
- except KeyboardInterrupt:
- print("Stopped by user")
From 4d24a1ab758d4aca9598f9e15a4c9d073d4645bf Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Fri, 28 Oct 2022 23:03:28 +0200
Subject: [PATCH 57/61] Delete method format_data in ApiManager class
---
tvguide/api.py | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/tvguide/api.py b/tvguide/api.py
index 462934a..0d20fc5 100644
--- a/tvguide/api.py
+++ b/tvguide/api.py
@@ -21,13 +21,3 @@ def get_data(relative_day: int) -> dict:
response = requests.get(api_link, headers=REQUEST_HEADER, cookies=REQUEST_COOKIES)
return response.json()
-
- @staticmethod
- def format_data(api_data: dict, verbose: bool) -> dict:
- formatted_data = {}
-
- for channel in api_data:
- temp_channel = Channel(channel, verbose)
- formatted_data.update({temp_channel.name: temp_channel})
-
- return formatted_data
From 839b3bda808a161145d3467916674d4f1fc927bf Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Fri, 28 Oct 2022 23:03:58 +0200
Subject: [PATCH 58/61] Rename main_v2.py to main.py
---
main_v2.py => main.py | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename main_v2.py => main.py (100%)
diff --git a/main_v2.py b/main.py
similarity index 100%
rename from main_v2.py
rename to main.py
From bcbefcc691ab60befbbce087690650dbf338d982 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Fri, 28 Oct 2022 23:19:22 +0200
Subject: [PATCH 59/61] Add type hints to all instance variables in TvGuide
class
---
tvguide/tvguide.py | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 5d95a64..5d20e6b 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -7,14 +7,14 @@
class TvGuide:
def __init__(self) -> None:
- self.relative_date = 0
- self.verbose = False
- self.show_now = False
- self.show_all_channels = False
- self.show_all_programs = False
- self.search_times = False
- self.search_categories = False
- self.search_names = False
+ self.relative_date: int = 0
+ self.verbose: bool = False
+ self.show_now: bool = False
+ self.show_all_channels: bool = False
+ self.show_all_programs: bool = False
+ self.search_times: bool = False
+ self.search_categories: bool = False
+ self.search_names: bool = False
self.input_times: List[str] = []
self.input_channels: List[str] = []
self.input_categories: List[str] = []
From 1ec963031de1a4779931f204ad4d22ab5ef61878 Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Fri, 28 Oct 2022 23:19:46 +0200
Subject: [PATCH 60/61] Rename instance variable "channels" to "all_channels"
in TvGuide class
---
tvguide/tvguide.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tvguide/tvguide.py b/tvguide/tvguide.py
index 5d20e6b..74b0660 100644
--- a/tvguide/tvguide.py
+++ b/tvguide/tvguide.py
@@ -19,7 +19,7 @@ def __init__(self) -> None:
self.input_channels: List[str] = []
self.input_categories: List[str] = []
self.input_search_terms: List[str] = []
- self.channels: List[Channel] = []
+ self.all_channels: List[Channel] = []
def parse_arguments(self, args: argparse.Namespace) -> None:
self.verbose = args.verbose
@@ -57,10 +57,10 @@ def parse_arguments(self, args: argparse.Namespace) -> None:
def parse_api_data(self, api_data: dict) -> None:
for channel_dict in api_data:
channel = Channel(channel_dict, self.verbose)
- self.channels.append(channel)
+ self.all_channels.append(channel)
def print_programs(self) -> None:
- channels = self.channels if self.show_all_channels else self.get_channels(self.input_channels)
+ channels = self.all_channels if self.show_all_channels else self.get_channels(self.input_channels)
for channel in channels:
print(f"\n{channel.name.upper()}")
@@ -94,7 +94,7 @@ def print_programs(self) -> None:
print()
def get_channels(self, channel_names: List[str]) -> List[Channel]:
- return [channel for channel in self.channels if channel.name in channel_names]
+ return [channel for channel in self.all_channels if channel.name in channel_names]
def _change_default_channels(self, channels: List[str]) -> None:
ConfigManager.change_defaults_user_channels(channels)
From b226984265ae699ad41b8f97a835c849ca24deca Mon Sep 17 00:00:00 2001
From: Crinibus <57172157+Crinibus@users.noreply.github.com>
Date: Wed, 2 Nov 2022 20:03:27 +0100
Subject: [PATCH 61/61] Simplify documentation of arguments in README
---
README.md | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 68ac8e3..5a60b9a 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Requires ```python3.9+```
An example on how to use this program:
```
-python3 main.py -c dr1 -c tv2 --all
+python3 main.py -c dr1 tv2 --all
```
This prints all the programs that run today for the channels DR1 and TV2.
@@ -23,7 +23,7 @@ This prints all the programs that run today for the channels DR1 and TV2.
Another example:
```
-python3 main.py -c dr1 -c tv2 -t 20:00 -d 1
+python3 main.py -c dr1 tv2 -t 20:00 -d 1
```
This prints only the tv-shows that start or is running at 8 pm the next day on the channels DR1 and TV2.
@@ -56,20 +56,23 @@ This prints the programs (with categories) that is currently running on the defa
## --channel
-By using the flag ```-c``` or ```--channel``` you specify which channels you want the program to show tv-shows from. Replace "[channel]" with wanted channel, e.g. "dr1".
-You can specify multiple channels just by using the ```-c``` flag again.
+By using the flag ```-c``` or ```--channel``` you specify which channels you want the program to show tv-shows from. Replace "[channel]" with wanted channel(s), e.g. "dr1".
If no channel(s) is chosen, the default channels is used. You can change the default channels as described [here](#--default-channels)
For example:
```
python3 main.py -c [channel_1] -c [channel_2]
```
+or
+```
+python3 main.py -c [channel_1] [channel_2]
+```
You can also specify "all" as the first channel to get all channels.
Examples:
```
-python3 main.py -c dr1 -c tv2 --all
+python3 main.py -c dr1 tv2 --all
```
This shows all the programs that run on DR1 and TV2 for today.
@@ -137,7 +140,7 @@ This shows all the programs that have the category "film" on the default channel
```
-python3 main.py --category film --category drama
+python3 main.py --category film drama
```
This shows all the programs that have either the category "film" or "drama" on the default channels for today.
@@ -180,7 +183,7 @@ This shows all the programs on the default channels for today that have the word
```
-python3 main.py --search avis --search vejr
+python3 main.py --search avis vejr
```
This shows all the programs on the default channels for today that have either the words "avis" or "vejr" in the title.