diff --git a/README.md b/README.md index c221919..3af504e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # python-zbMathRest2Oai Read data from the zbMATH Open API https://api.zbmath.org/docs and feed it to the OAI-PMH server https://oai.portal.mardi4nfdi.de/oai/ + +Hint for a proper installation: + +_ point to the directory +_ execute "pip install -e requirements.txt" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e69de29..945c9b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/src/zbmath_rest2oai/getWithSwagger.py b/src/zbmath_rest2oai/getWithSwagger.py index c2c25d9..9c2d3cc 100644 --- a/src/zbmath_rest2oai/getWithSwagger.py +++ b/src/zbmath_rest2oai/getWithSwagger.py @@ -1,7 +1,44 @@ import swagger_client from zbmath_rest2oai.xml_writer import create_document +from xml.dom import minidom api_instance = swagger_client.DocumentApi(swagger_client.ApiClient()) res = api_instance.get_document_by_zbmath_id_document_id_get(id="6383667") doc = res.result -print(create_document(doc).toprettyxml()) +xmld = create_document(doc) + + +ron = xmld.createElement("oai_zb_preview:zbmath") +ron.setAttributeNS( + "xmls", + "xmlns:oai_zb_preview", + "https://zbmath.org/OAI/2.0/oai_zb_preview/", +) +ron.setAttributeNS( + "xmls", + "xmlns:zbmath", + "https://zbmath.org/zbmath/elements/1.0/", +) +ron.setAttributeNS( + "xmls", + "xmlns:xsi", + "http://www.w3.org/2001/XMLSchema-instance", +) + +def append_text_child(xmld, parent, name, value): + """ + Creates new text node and appends it to parent + :param xmld: + :param parent: the node to append to + :param name: + :param value: + """ + x_elem = xmld.createElement(f"zbmath:{0}".format(name)) + text = xmld.createTextNode(str(value)) + x_elem.appendChild(text) + parent.appendChild(x_elem) + return parent + +final_xml = append_text_child(xmld, ron, 'id', (res.result.id)) + +print(final_xml.toprettyxml()) \ No newline at end of file