-
Notifications
You must be signed in to change notification settings - Fork 3
/
ark2isbd.py
43 lines (34 loc) · 1.38 KB
/
ark2isbd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# coding: utf-8
explain = "Fourniture de notices ISBD à partir d'une liste d'ARKs"
import SRUextraction as sru
from lxml import etree
ns = {"m": "http://catalogue.bnf.fr/namespaces/InterXMarc"}
def convert_xml2isbd(xml_isbn_record, sep="\n"):
text_record = []
for node in xml_isbn_record.xpath("m:notice_isbd/*", namespaces=ns):
node_text = []
for subnode in node.xpath(".//*"):
if subnode.text is not None:
node_text.append(subnode.text)
node_text = "".join(node_text)
text_record.append(node_text)
text_record = [el for el in text_record if el.strip()]
if sep is not None:
text_record = sep.join(text_record)
return text_record
def list_ark2isbd(list_arks):
dict_arks2isbd = {}
for ark in list_arks:
result = sru.SRU_result(f"idPerenne any \"{ark}\"", "http://noticesservices.bnf.fr/SRU", {"recordSchema": "ISBD"})
if result.firstRecord is not None:
text_isbn = convert_xml2isbd(result.firstRecord)
dict_arks2isbd[ark] = text_isbn
return dict_arks2isbd
if __name__ == "__main__":
list_arks = input("Liste des ARKs à extraire sous forme de notices ISBD (sep : espace ou virgule): ")
if " " in list_arks:
list_arks = list_arks.split(" ")
else:
list_arks = list_arks.split(",")
records = list_ark2isbd(list_arks)
print(records)