exit if results list is empty (or is cleared during filtering)

This commit is contained in:
hygienic-books 2022-03-17 01:50:19 +01:00
parent 32932fe803
commit 0f68ef558e

View File

@ -29,6 +29,7 @@ JSONType = t.Union[str, int, float, bool, None, t.Dict[str, t.Any], t.List[t.Any
# Exit codes # Exit codes
# 1: Config file invalid, it has no sections # 1: Config file invalid, it has no sections
# 2: Config file invalid, sections must define at least CONST.CFG_MANDATORY # 2: Config file invalid, sections must define at least CONST.CFG_MANDATORY
# 3: No search results to download
class CONST(object): class CONST(object):
@ -204,12 +205,20 @@ def get_json_response(
return got_json_response return got_json_response
def no_downloads_needed() -> None:
log.info(f"No search results to download, exiting 3 ...")
sys.exit(3)
def remove_result( def remove_result(
json_obj: MVWJSONResponse, json_obj: MVWJSONResponse,
result_obj: type_def.mvw_json_response.Show) -> MVWJSONResponse: result_obj: type_def.mvw_json_response.Show) -> MVWJSONResponse:
json_obj.result.results.remove(result_obj) json_obj.result.results.remove(result_obj)
json_obj.result.queryInfo.resultCount -= 1 json_obj.result.queryInfo.resultCount -= 1
return json_obj if json_obj.result.queryInfo.resultCount:
return json_obj
else:
no_downloads_needed()
def log_result_count(result_count: int, pre_filter: bool = True) -> None: def log_result_count(result_count: int, pre_filter: bool = True) -> None:
@ -309,4 +318,9 @@ if __name__ == '__main__':
log.debug(f"Deduplicating results by title where needed ...") log.debug(f"Deduplicating results by title where needed ...")
if config.has_option(section, "title_not_regex"): if config.has_option(section, "title_not_regex"):
json_response = dedup_json_titles(section, config, json_response) json_response = dedup_json_titles(section, config, json_response)
# console.print_json(json_response.json())
#if json_response.result.queryInfo.resultCount:
# log.debug(f"Downloading shows ...")
#else
#
# # console.print_json(json_response.json())