Example #1
0
def extract1record(row, j, form, headers, parametres):
    identifier = funcs.Id4record(row, parametres)
    if (len(identifier.aligned_id.clean) > 1
            and identifier.aligned_id.clean not in parametres["listeARK_BIB"]):
        print(str(j) + ". " + identifier.aligned_id.clean)
        parametres["listeARK_BIB"].append(identifier.aligned_id.clean)
        url_record = ark2url(identifier, parametres)
        if url_record:
            (test, page) = funcs.testURLetreeParse(url_record)
            if (test):
                nbResults = page2nbresults(page, identifier)
                # Si on part d'un ARK
                if (nbResults == "1" and identifier.aligned_id.type == "ark"):
                    for XMLrec in page.xpath(
                            "//srw:record/srw:recordData/mxc:record",
                            namespaces=main.ns):
                        record2file(identifier, XMLrec, parametres["bib_file"],
                                    parametres["format_file"], parametres)
                        if (parametres["AUTliees"] > 0):
                            bib2aut(identifier, XMLrec, parametres)
                # Si on part d'un PPN
                elif (nbResults == "1"
                      and identifier.aligned_id.type == "ppn"):
                    for XMLrec in page.xpath("//record"):
                        record2file(identifier, XMLrec, parametres["bib_file"],
                                    parametres["format_file"], parametres)
                        if (parametres["AUTliees"] > 0):
                            bib2aut(identifier, XMLrec, parametres)
            elif (identifier.aligned_id.type == "ppn"
                  and parametres["type_records"] == "bib"):
                ppn_updated = update_bib_ppn(identifier.aligned_id.clean)
                if ppn_updated is not None:
                    print("Nouveau PPN :", ppn_updated)
                    errors_list.append([
                        f"Fusion de notices Sudoc\t{identifier.aligned_id.init} disparu. Nouveau PPN : {ppn_updated}",
                        ""
                    ])
                    identifier = funcs.Id4record([row[0], f"PPN{ppn_updated}"],
                                                 parametres)
                    parametres["listeARK_BIB"].append(
                        identifier.aligned_id.clean)
                    url_record = ark2url(identifier, parametres)
                    if url_record:
                        (test, page) = funcs.testURLetreeParse(url_record)
                        if (test):
                            nbResults = page2nbresults(page, identifier)
                            if (nbResults == "1"):
                                for XMLrec in page.xpath("//record"):
                                    record2file(identifier, XMLrec,
                                                parametres["bib_file"],
                                                parametres["format_file"],
                                                parametres)
                                    if (parametres["AUTliees"] > 0):
                                        bib2aut(identifier, XMLrec, parametres)
Example #2
0
def bib2aut(identifier, XMLrecord, parametres, multiprocess):
    """Si une des option "Récupérer les notices d'autorité liées" est cochée
    récupération des identifiants de ces AUT pour les récupérer"""
    source = "bnf"
    if (identifier.aligned_id.type == "ppn"):
        source = "sudoc"
    liste_nna = []
    listefields = []
    linked_aut_record = []
    format_marc = parametres["format_BIB"].split("x")[0]
    linked_aut_records = []
    if (parametres["AUTlieesAUT"] == 1):
        listefields.extend(listefieldsLiensAUT[format_marc])
    if (parametres["AUTlieesSUB"] == 1):
        listefields.extend(listefieldsLiensSUB[format_marc])
    if (parametres["AUTlieesWORK"] == 1):
        listefields.extend(listefieldsLiensWORK[format_marc])
    for field in listefields:
        liste_nna.extend(
            extract_nna_from_bib_record(XMLrecord, field, source, parametres))
    for nna in liste_nna:
        if (source == "sudoc"):
            source = "idref"
        url = nn2url(nna, "aut", parametres, source)
        (test, record) = funcs.testURLetreeParse(url)
        if (test and source == "bnf"
                and record.find("//srw:recordData/mxc:record",
                                namespaces=main.ns) is not None):
            XMLrec = record.xpath(".//srw:recordData/mxc:record",
                                  namespaces=main.ns)[0]
            linked_identifier = funcs.Id4record([
                record.find("//srw:recordIdentifier", namespaces=main.ns).text
            ])
            # record2file(linked_identifier, XMLrec, parametres["aut_file"],
            #             parametres["format_file"], parametres)
            linked_aut_record.append([linked_identifier, XMLrec])
        elif (test and source == "idref"
              and record.find("leader") is not None):
            # record2file(f"PPN{nna}", record, parametres["aut_file"],
            #             parametres["format_file"], parametres)
            linked_aut_record.append([f"PPN{nna}", record])
        if multiprocess:
            for el in linked_aut_record:
                el[1] = etree.tostring(el[1])
        return linked_aut_record