Populate local MDCS instance with student data and metadata

Import MDCS API tool module


In [ ]:
import mdcs

Host and user information


In [ ]:
user='admin'
pswd='admin'
host='http://127.0.0.1:8000'
template_name='TEM-Tutorial'

List of file prefixes for micrograph images and XML metadata


In [ ]:
name_list=[
    "Al6061_DF_343C",
    "Al6061_SAED_343C",
    "Al6061-BF-343C",
    "CoAl-W-900-1000h-SAED",
    "CoAlW-900-1000h",
    "TRIP700-750C-carbide-SAED",
    "TRIP700-carbide-750C-DF",
    "TRIP700-Wferrite-750C"]

For each name in the list:

  • Upload micrograph
  • Read XML metadata
  • Replace generic URL with unique URL for micrograph
  • Upload XML metadata record

In [ ]:
for name in name_list:
    xml_name=name+".xml"
    jpg_name=name+".jpg"
    
    print "Uploading:",jpg_name
    url = mdcs.blob.upload(jpg_name,host,user,pswd)
    
    print "Reading:",xml_name
    with open(xml_name, 'r') as f: 
        content = f.read()
    content = content.replace("http://127.0.0.1:8000/rest/blob?id=REPLACE-ME-BLOB-ID",url)
    
    print "Uploading:",xml_name
    response = mdcs.curate_as(xml_name,name,host,user,pswd,template_title=template_name,content=content)
    print "Response:",response

In [ ]: