Skip to content

Commit

Permalink
Use python Rest client
Browse files Browse the repository at this point in the history
Use swagger generated code to interact with the zbMATH Rest API
  • Loading branch information
physikerwelt committed Nov 1, 2023
1 parent 4a58ad7 commit 7939c79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "zbmath_rest2oai"
description = "convert from custom api to oai-pmh api"
dynamic = ["version"]
dependencies = [
"requests"
"swagger_client @ git+https://github.com/zbMATHOpen/zbRestApiClient.git"
]
[project.optional-dependencies]
test = [
Expand Down
11 changes: 0 additions & 11 deletions src/zbmath_rest2oai/getPublicationInfo.py

This file was deleted.

7 changes: 7 additions & 0 deletions src/zbmath_rest2oai/getWithSwagger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import swagger_client
from zbmath_rest2oai.xml_writer import create_document

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())
6 changes: 4 additions & 2 deletions src/zbmath_rest2oai/xml_writer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from xml.dom import minidom # Create XML document

from swagger_client import AllOfzbmathApiDataModelsDisplayDocumentsResultIDResult as Doc

def create_document(json: dict):

def create_document(doc: Doc):
xmld = minidom.Document()
root = xmld.createElement("root")
root.appendChild(xmld.createTextNode( str ( json.get('result').get('id')) ))
root.appendChild(xmld.createTextNode(str(doc.id)))
xmld.appendChild(root)
return xmld

0 comments on commit 7939c79

Please sign in to comment.