src/pds_doi_service/core/outputs/osti/osti_web_parser.py
def parse_dois_from_label(label_text, content_type=CONTENT_TYPE_XML):
        """
        Parses a response from a GET (query) or a PUT to the OSTI server
        (in XML query format) and return a list of dictionaries.

        By default, all possible fields are extracted. If desire to only extract
        smaller set of fields, they should be specified accordingly.
        Specific fields are extracted from input. Not all fields in XML are used.

        """
        dois = []
        errors = {}

        doc = etree.fromstring(label_text.encode())
        my_root = doc.getroottree()

        # Trim down input to just fields we want.
        for index, record_element in enumerate(my_root.findall("record")):
            status = record_element.get("status")

            if status is None:
                raise InputFormatException(
                    f"Could not parse a status for record {index + 1} from the " f"provided OSTI XML."
                )

            if status.lower() == "error":
                # The 'error' record is parsed differently and does not have all
                # the attributes we desire.
                logger.error(f"Errors reported for record index {index + 1}")

                # Check for any errors reported back from OSTI and save
                # them off to be returned
                errors_element = record_element.xpath("errors")
                doi_message = record_element.xpath("doi_message")

                cur_errors = []

                if len(errors_element):
                    for error_element in errors_element[0]:
                        cur_errors.append(error_element.text)

                if len(doi_message):
                    cur_errors.append(doi_message[0].text)

                errors[index] = cur_errors

            identifier = DOIOstiXmlWebParser._get_identifier(record_element)

            timestamp = datetime.now()

            publication_date = record_element.xpath("publication_date")[0].text
            product_type = record_element.xpath("product_type")[0].text
            product_type_specific = record_element.xpath("product_type_specific")[0].text

            doi = Doi(
                title=record_element.xpath("title")[0].text,
                publication_date=datetime.strptime(publication_date, "%Y-%m-%d"),
                product_type=ProductType(product_type),
                product_type_specific=product_type_specific,
                pds_identifier=identifier,
                status=DoiStatus(status.lower()),
                date_record_added=timestamp,
                date_record_updated=timestamp,
            )

            # Parse for some optional fields that may not be present in
            # every record from OSTI.
            doi = DOIOstiXmlWebParser._parse_optional_fields(doi, record_element)

            dois.append(doi)

        return dois, errors

        Parses a response from a GET (query) or a PUT to the OSTI server
        (in XML query format) and return a list of dictionaries.

        By default, all possible fields are extracted. If desire to only extract
        smaller set of fields, they should be specified accordingly.
        Specific fields are extracted from input. Not all fields in XML are used.

        
Parses a response from a GET (query) or a PUT to the OSTI server
(in XML query format) and return a list of dictionaries.

By default, all possible fields are extracted. If desire to only extract
smaller set of fields, they should be specified accordingly.
Specific fields are extracted from input. Not all fields in XML are used.
Parses a response from a GET ( query ) or a PUT to the OSTI server ( in XML query format ) and return a list of dictionaries . By default all possible fields are extracted . If desire to only extract smaller set of fields they should be specified accordingly . Specific fields are extracted from input . Not all fields in XML are used .
def parse_dois_from_label(label_text, content_type=CONTENT_TYPE_XML):
        dois = []
        errors = {}
        doc = etree.fromstring(label_text.encode())
        my_root = doc.getroottree()
        for index, record_element in enumerate(my_root.findall("record")):
            status = record_element.get("status")
            if status is None:
                raise InputFormatException(
                    f"Could not parse a status for record {index + 1} from the " f"provided OSTI XML."
                )
            if status.lower() == "error":
                logger.error(f"Errors reported for record index {index + 1}")
                errors_element = record_element.xpath("errors")
                doi_message = record_element.xpath("doi_message")
                cur_errors = []
                if len(errors_element):
                    for error_element in errors_element[0]:
                        cur_errors.append(error_element.text)
                if len(doi_message):
                    cur_errors.append(doi_message[0].text)
                errors[index] = cur_errors
            identifier = DOIOstiXmlWebParser._get_identifier(record_element)
            timestamp = datetime.now()
            publication_date = record_element.xpath("publication_date")[0].text
            product_type = record_element.xpath("product_type")[0].text
            product_type_specific = record_element.xpath("product_type_specific")[0].text
            doi = Doi(
                title=record_element.xpath("title")[0].text,
                publication_date=datetime.strptime(publication_date, "%Y-%m-%d"),
                product_type=ProductType(product_type),
                product_type_specific=product_type_specific,
                pds_identifier=identifier,
                status=DoiStatus(status.lower()),
                date_record_added=timestamp,
                date_record_updated=timestamp,
            )
            doi = DOIOstiXmlWebParser._parse_optional_fields(doi, record_element)
            dois.append(doi)
        return dois, errors
def parse_dois_from_label ( label_text , content_type = CONTENT_TYPE_XML ) : dois = [ ] errors = { } doc = etree . fromstring ( label_text . encode ( ) ) my_root = doc . getroottree ( ) for index , record_element in enumerate ( my_root . findall ( "record" ) ) : status = record_element . get ( "status" ) if status is None : raise InputFormatException ( f"Could not parse a status for record {index + 1} from the " f"provided OSTI XML." ) if status . lower ( ) == "error" : logger . error ( f"Errors reported for record index {index + 1}" ) errors_element = record_element . xpath ( "errors" ) doi_message = record_element . xpath ( "doi_message" ) cur_errors = [ ] if len ( errors_element ) : for error_element in errors_element [ 0 ] : cur_errors . append ( error_element . text ) if len ( doi_message ) : cur_errors . append ( doi_message [ 0 ] . text ) errors [ index ] = cur_errors identifier = DOIOstiXmlWebParser . _get_identifier ( record_element ) timestamp = datetime . now ( ) publication_date = record_element . xpath ( "publication_date" ) [ 0 ] . text product_type = record_element . xpath ( "product_type" ) [ 0 ] . text product_type_specific = record_element . xpath ( "product_type_specific" ) [ 0 ] . text doi = Doi ( title = record_element . xpath ( "title" ) [ 0 ] . text , publication_date = datetime . strptime ( publication_date , "%Y-%m-%d" ) , product_type = ProductType ( product_type ) , product_type_specific = product_type_specific , pds_identifier = identifier , status = DoiStatus ( status . lower ( ) ) , date_record_added = timestamp , date_record_updated = timestamp , ) doi = DOIOstiXmlWebParser . _parse_optional_fields ( doi , record_element ) dois . append ( doi ) return dois , errors
Parses a response from a GET (query) or a PUT to the OSTI server
(in XML query format) and return a list of dictionaries.
Parses a response from a GET ( query ) or a PUT to the OSTI server ( in XML query format ) and return a list of dictionaries .
"""
        Parses a response from a GET (query) or a PUT to the OSTI server
        (in XML query format) and return a list of dictionaries.

        By default, all possible fields are extracted. If desire to only extract
        smaller set of fields, they should be specified accordingly.
        Specific fields are extracted from input. Not all fields in XML are used.

        """ # Trim down input to just fields we want. # The 'error' record is parsed differently and does not have all # the attributes we desire. # Check for any errors reported back from OSTI and save # them off to be returned # Parse for some optional fields that may not be present in # every record from OSTI.
label_text
content_type