From 8704745fdc150763145244fee522015dee546eb0 Mon Sep 17 00:00:00 2001 From: WolfwithSword <12175651+WolfwithSword@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:16:24 -0300 Subject: [PATCH 1/6] add config-file cli parameter --- main.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index db508c3..7c59f0e 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,9 @@ +import os +import argparse +import sys + import asyncio import time -import os from datetime import datetime import logging @@ -17,9 +20,26 @@ logging.basicConfig(level=logging.INFO) logger = logging.getLogger("tcn-main") -config = TCNConfig() cwd = os.getcwd() config_path = os.path.join(cwd, 'config.ini') + +argv = sys.argv +conf_parser = argparse.ArgumentParser( + description=__doc__, # -h/--help + formatter_class=argparse.RawDescriptionHelpFormatter, + add_help=False + ) +conf_parser.add_argument("-c", "--conf_file", help="Specify config file", metavar="FILE") +args, remaining_argv = conf_parser.parse_known_args() + +if args.conf_file: + if os.path.isfile(args.conf_file): + logger.info(f"Using config file: {args.conf_file}") + config_path = args.conf_file + else: + logger.warning(f"Could not use config path `{args.conf_file}`. Using default file and values") + +config = TCNConfig() config.setup(path=config_path) if not config.primary_channelnames: From 17005a0fcbc463a8cb1c39e972a0c14cb2555f0d Mon Sep 17 00:00:00 2001 From: WolfwithSword <12175651+WolfwithSword@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:19:15 -0300 Subject: [PATCH 2/6] add config-file cli parameter --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 98657ce..b62bde6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ lib/ *.zip .tcn-cache/ *.db +test.config.ini # Byte-compiled / optimized / DLL files __pycache__/ From 2d6479ca685aa6534f1444056118a7cb88e1b7e2 Mon Sep 17 00:00:00 2001 From: WolfwithSword <12175651+WolfwithSword@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:49:45 -0300 Subject: [PATCH 3/6] add output-file cli parameter --- README.md | 14 ++++++++++++++ main.py | 29 ++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a89a6a2..9495400 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,20 @@ user_expiry_s: `3600` number of seconds to keep user API results from twitch bef vodlist_expiry_s: `600` number of seconds to keep list of user's vods with tagged users from twitch API before expiring. Can be long, but if a new public vod goes up, it won't be picked up until this expires +### CLI Parameters + +- **-c \** | **--conf_file \** + - Accepts a filepath for a config file to use instead of the default `config.ini` found next to the program +- **-o \** | **--output_file \ Date: Fri, 23 Aug 2024 16:49:54 -0300 Subject: [PATCH 4/6] add output-file cli parameter --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b62bde6..5b38aca 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ lib/ .tcn-cache/ *.db test.config.ini +output/ # Byte-compiled / optimized / DLL files __pycache__/ From d7f04917d3320fd95c0df8e864e6d097d16bf882 Mon Sep 17 00:00:00 2001 From: WolfwithSword <12175651+WolfwithSword@users.noreply.github.com> Date: Fri, 23 Aug 2024 16:54:48 -0300 Subject: [PATCH 5/6] config path check --- main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.py b/main.py index 0d5487d..bde9e70 100644 --- a/main.py +++ b/main.py @@ -42,6 +42,10 @@ else: logger.warning(f"Could not use config path `{args.conf_file}`. Using default file and values") +if not os.path.isfile(config_path): + logger.error("No valid config file was found. Please setup a valid config file") + quit() + config = TCNConfig() config.setup(path=config_path) From c607f8b088c8b0586b9d404e732fa0e6fdc0b1d8 Mon Sep 17 00:00:00 2001 From: WolfwithSword <12175651+WolfwithSword@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:47:49 -0300 Subject: [PATCH 6/6] cleanup --- main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index bde9e70..013d9bc 100644 --- a/main.py +++ b/main.py @@ -18,6 +18,10 @@ from helpers.twitch_utils import TwitchUtils from helpers.utils import chunkify, time_since +######### +# Setup # +######### + logging.basicConfig(level=logging.INFO) logger = logging.getLogger("tcn-main") @@ -65,9 +69,12 @@ OUTPUT_FILE = args.output_file logger.info(f"Output will go to: {OUTPUT_FILE}") +################ +# End of Setup # +################ # Each user lookup is always two api requests. First is for user check, second is for video archives check. -# So N=500 users, means 1000 API requests +# So N=500 users, means 1000 API requests. Mitigated if using disk cache. async def twitch_run(): @@ -141,7 +148,9 @@ async def twitch_run(): net = Network(notebook=False, height="1500px", width="100%", bgcolor="#222222", font_color="white", - heading=f"Twitch Collab Network: {','.join(config.primary_channelnames)}
{datetime.today().strftime('%Y-%m-%d')}
Depth: {depth}, Connections: {len(users)}", + heading=f"Twitch Collab Network: {','.join(config.primary_channelnames)}" + f"
{datetime.today().strftime('%Y-%m-%d')}" + f"
Depth: {depth}, Connections: {len(users)}", select_menu=False, filter_menu=True, neighborhood_highlight=True) net.from_nx(G) options = '{"nodes": {"borderWidth": 5}}'