From 78937820a82931baffb02c145b37c95af71b44bc Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Fri, 27 Oct 2023 11:44:26 -0700 Subject: Move batch file processing to parse module --- src/wikiget/parse.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/wikiget/parse.py') diff --git a/src/wikiget/parse.py b/src/wikiget/parse.py index 52cc262..998136a 100644 --- a/src/wikiget/parse.py +++ b/src/wikiget/parse.py @@ -59,3 +59,19 @@ def get_dest(dl: str, args: Namespace) -> File: file = File(filename, dest, site_name) return file + + +def read_batch_file(batch_file: str) -> dict[int, str]: + dl_list = {} + + logger.info(f"Using batch file '{batch_file}'.") + + with open(batch_file) as fd: + # read the file into memory and process each line as we go + for line_num, line in enumerate(fd, start=1): + line_s = line.strip() + # ignore blank lines and lines starting with "#" (for comments) + if line_s and not line_s.startswith("#"): + dl_list[line_num] = line_s + + return dl_list -- cgit v1.2.3