The ‘Create a CompositeResource Resource’ feature allows the user to create a new CompositeResource resource in their HydroShare account, which would contain all files they intend to upload. The resources in the user’s HydroShare account are created with a certain amount of prerequisites like author name, keywords, metadata and the title of your resource. The Python API provided by HydroShare helps in completing this task. Below are step by step instructions on how to create a new resource.
To try this on your own, you can use the code snippet below that is used in this demonstration.
from hs_restclient import HydroShare, HydroShareAuthBasic
auth = HydroShareAuthBasic(username= 'username', password= 'password')
hs = HydroShare(auth=auth)
abstract = date_built
keywords = owner.split(', ')
rtype = 'CompositeResource'
fpath = '/path/to/a/file'
metadata = '[{"coverage":{"type":"period", "value":{"start":"01/01/2000", "end":"12/12/2010"}}}, {"creator":{"name":"Username"}}, {"creator":{"name":"Username2"}}]'
extra_metadata = '{"key-1": "value-1", "key-2": "value-2"}'
resource_id = hs.createResource(rtype, title, resource_file=fpath, keywords=keywords, abstract=abstract, metadata=metadata, extra_metadata=extra_metadata)
messages.error(request, "Resource created successfully")
if has_errors:
messages.error(request, "Please fix errors.")