From d4ed997b0a609db89046b61fb2d06264c7dedc10 Mon Sep 17 00:00:00 2001 From: ErnestaP Date: Wed, 24 Apr 2024 15:25:31 +0200 Subject: [PATCH] total amount of recs is not found --- dags/common/exceptions.py | 7 +++++++ dags/open_access/utils.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dags/common/exceptions.py b/dags/common/exceptions.py index 199a119..a0b15bd 100644 --- a/dags/common/exceptions.py +++ b/dags/common/exceptions.py @@ -8,3 +8,10 @@ def __init__(self, input, current_year): class DataFetchError(Exception): def __init__(self, status_code, url): super().__init__(f"Data fetch failure, status_code={status_code}, url={url}") + + +class NotFoundTotalCountOfRecords(Exception): + def __init__( + self, + ): + super().__init__("Total count of records is not found!") diff --git a/dags/open_access/utils.py b/dags/open_access/utils.py index 1e916e3..f2d63af 100644 --- a/dags/open_access/utils.py +++ b/dags/open_access/utils.py @@ -4,7 +4,7 @@ import backoff import requests -from common.exceptions import DataFetchError, WrongInput +from common.exceptions import DataFetchError, NotFoundTotalCountOfRecords, WrongInput from open_access.parsers import get_golden_access_records_ids @@ -29,7 +29,7 @@ def get_gold_access_count(total, url): count = count + 1 response = get_data(full_url) if response.status_code != 200: - raise DataFetchError(url, response.status_code) + raise DataFetchError(urls=url, status_code=response.status_code) golden_access_records_ids_count = golden_access_records_ids_count + len( get_golden_access_records_ids(response.text) ) @@ -46,7 +46,7 @@ def get_total_results_count(data): total_records_count = match.group(1) return int(total_records_count) except AttributeError: - return 0 + raise NotFoundTotalCountOfRecords closed_access_query = (