Last active
March 19, 2019 21:41
-
-
Save csjx/48df26224bcf4740c73f796b5d920352 to your computer and use it in GitHub Desktop.
Python example of DataONE CN.getSystemMetadata()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
from d1_client.cnclient_2_0 import CoordinatingNodeClient_2_0 | |
from d1_common.types import dataoneTypes | |
import os | |
# Set up the CN client with a token | |
token = os.environ["token"] | |
headers = {"Authorization": "Bearer " + token} | |
base_url = "https://cn.dataone.org/cn" | |
cn = CoordinatingNodeClient_2_0(base_url, headers = headers) | |
# Limit the objects listed | |
count = 100 | |
nodeId = "urn:node:ESS_DIVE" | |
# Get an object list | |
object_list = cn.listObjects(count = count, nodeId = nodeId) | |
# Get system metadata for each object | |
for objectinfo in object_list.content(): | |
try: | |
sysmeta = cn.getSystemMetadata(objectinfo.identifier.value()) | |
print(sysmeta.identifier.value()) | |
print("----------------------------------------------------") | |
# Get the list of replicas | |
replicas = sysmeta.replica | |
# Show each replica status of the object | |
for replica in replicas: | |
node = replica.replicaMemberNode.value() | |
status = replica.replicationStatus | |
verified = str(replica.replicaVerified) | |
print("{}\t{}\t{}".format(node, status, verified)) | |
print("\n") | |
except IOError as ioe: | |
print(ioe) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment