def get_total_expected_records(base_url):
    ' Retrieve the total number of expected records based on the last paginated URL '
    initial_request = get_with_exception_hand(base_url, expect_entries=False)
    initial_request_xml = xmltodict.parse(initial_request.text, process_namespaces=True, namespaces=FPDS_NAMESPACES)
    try:
        urls_list = list_data(initial_request_xml['feed']['link'])
    except KeyError:
        urls_list = []
    final_request_url = None
    for url in urls_list:
        if (url['@rel'] == 'last'):
            final_request_url = url['@href']
            continue
    if (not final_request_url):
        try:
            return len(list_data(initial_request_xml['feed']['entry']))
        except KeyError:
            return 0
    final_request_count = int(final_request_url.split('&start=')[(- 1)])
    final_request = get_with_exception_hand(final_request_url)
    final_request_xml = xmltodict.parse(final_request.text, process_namespaces=True, namespaces=FPDS_NAMESPACES)
    try:
        entries_list = list_data(final_request_xml['feed']['entry'])
    except KeyError:
        raise Exception('Initial count failed, no entries in last page of request.')
    return (final_request_count + len(entries_list))
Retrieve the total number of expected records based on the last paginated URL
def get_total_expected_records(base_url):
    '  '
    initial_request = get_with_exception_hand(base_url, expect_entries=False)
    initial_request_xml = xmltodict.parse(initial_request.text, process_namespaces=True, namespaces=FPDS_NAMESPACES)
    try:
        urls_list = list_data(initial_request_xml['feed']['link'])
    except KeyError:
        urls_list = []
    final_request_url = None
    for url in urls_list:
        if (url['@rel'] == 'last'):
            final_request_url = url['@href']
            continue
    if (not final_request_url):
        try:
            return len(list_data(initial_request_xml['feed']['entry']))
        except KeyError:
            return 0
    final_request_count = int(final_request_url.split('&start=')[(- 1)])
    final_request = get_with_exception_hand(final_request_url)
    final_request_xml = xmltodict.parse(final_request.text, process_namespaces=True, namespaces=FPDS_NAMESPACES)
    try:
        entries_list = list_data(final_request_xml['feed']['entry'])
    except KeyError:
        raise Exception('Initial count failed, no entries in last page of request.')
    return (final_request_count + len(entries_list))