Skip to content

Instantly share code, notes, and snippets.

@alarictabaries
Last active December 14, 2023 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alarictabaries/f8025d12512735c6b5550596142d9595 to your computer and use it in GitHub Desktop.
Save alarictabaries/f8025d12512735c6b5550596142d9595 to your computer and use it in GitHub Desktop.
import epo_ops
import xml.etree.ElementTree as ET
# https://link.epo.org/web/how_to_test_OPS_en.pdf
client = epo_ops.Client(key='', secret='') # Instantiate client
response = client.published_data_search('in all "alaric tabaries"', range_begin=1, range_end=25, constituents=None)
documents = []
print(response)
if response.ok:
res = response.content
xml_data = res.decode('utf-8')
print(xml_data)
# Parse the XML
root = ET.fromstring(xml_data)
# Namespaces
namespaces = {
'ops': 'http://ops.epo.org',
'default': 'http://www.epo.org/exchange'
}
# Iterate through each <ops:search-result>
for search_result in root.findall('.//ops:search-result', namespaces):
for publication_ref in search_result.findall('.//ops:publication-reference', namespaces):
family_id = publication_ref.attrib.get('family-id')
print(f"Family ID: {family_id}")
document_id = publication_ref.find('.//default:document-id', namespaces)
if document_id is not None:
country = document_id.find('default:country', namespaces).text
doc_number = document_id.find('default:doc-number', namespaces).text
kind = document_id.find('default:kind', namespaces).text
print(f"Country: {country}, Document Number: {doc_number}, Kind: {kind}")
documents.append({"country": country, "doc_number": doc_number, "kind": kind})
else:
print("Document ID not found")
for doc in documents:
response = client.published_data( # Retrieve bibliography data
reference_type='publication', # publication, application, priority
input=epo_ops.models.Docdb(doc["doc_number"], doc["country"], doc["kind"]), # original, docdb, epodoc
endpoint='biblio', # optional, defaults to biblio in case of published_data
constituents=[] # optional, list of constituents
)
xml_data = response.content.decode('utf-8')
print(xml_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment