Find Artist and Additional Album Release Info
[1]:
# Find an Asset and create Events
#
# Main function, establishes a connection to DataTrails using an App Registration then uses that
# to find an Asset and create Events.
#
# Note: The purpose of DataTrails Jupyter Notebooks is to provide simplified examples that one can easily execute and digest.
# The DataTrails Python SDK is authored to work cleanly with more advanced coding techniques.
#
# DataTrails Python SDK: https://github.com/datatrails/datatrails-python
#
[2]:
from json import dumps as json_dumps
from os import getenv
from archivist.archivist import Archivist
from archivist.logger import set_logger
[3]:
%reload_ext dotenv
%dotenv -o notebooks.env
[4]:
# DATATRAILS_URL, DATATRAILS_APPREG_CLIENT, DATATRAILS_APPREG_SECRET are environment variables that represent connection parameters.
#
# DATATRAILS_URL = represents the url to the DataTrails application
# DATATRAILS_APPREG_CLIENT = represents the client ID from an Application Registration
# DATATRAILS_APPREG_SECRET = represents the client secret from an Application Registration
# DATATRAILS_UNIQUE_ID = is an environment variable that is a unique identifier
DATATRAILS_URL = getenv("DATATRAILS_URL")
DATATRAILS_APPREG_CLIENT = getenv("DATATRAILS_APPREG_CLIENT")
DATATRAILS_APPREG_SECRET = getenv("DATATRAILS_APPREG_SECRET")
DATATRAILS_UNIQUE_ID = getenv("DATATRAILS_UNIQUE_ID")
if not DATATRAILS_UNIQUE_ID:
raise Exception("DATATRAILS_UNIQUE_ID is undefined")
[5]:
"""
Main function of Asset and Event creation.
* Connect to DataTrails with client ID and client secret
* Creates an Asset and two Events
* Prints response of Asset and Event creation
"""
# Optional call to set the logger level. The argument can be either
# "INFO" or "DEBUG". For more sophisticated logging control see our
# documentation.
set_logger("INFO")
# Initialize connection to DATATRAILS
print("Connecting to DATATRAILS")
print("DATATRAILS_URL", DATATRAILS_URL)
arch = Archivist(
DATATRAILS_URL, (DATATRAILS_APPREG_CLIENT, DATATRAILS_APPREG_SECRET), max_time=300
)
Connecting to DATATRAILS
DATATRAILS_URL https://app.datatrails.ai
[6]:
def get_artist(arch, name, artistid):
"""
Finds existing Artist asset by name and unique id
"""
attrs = {
"arc_display_type": "Artists",
"arc_display_name": name,
"artistid": artistid,
}
return arch.assets.read_by_signature(attrs=attrs)
[7]:
def create_release(arch, asset, album_name, release):
"""
Creates an Event for existing Artist asset
"""
props = {"operation": "Record", "behaviour": "RecordEvidence"}
attrs = {
"arc_description": "Artist Information for existing Artist",
"arc_display_type": "Album Release for existing Artist",
"album_name": album_name,
"relase_year": release,
}
return arch.events.create(asset["identity"], props=props, attrs=attrs)
[8]:
# Finding existing artist by name and artist id
print("Finding Asset")
asset = get_artist(arch, "Adele Laurie Blue Adkins", DATATRAILS_UNIQUE_ID)
print("Asset", json_dumps(asset, indent=4))
Finding Asset
Refresh token
Asset {
"identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f",
"behaviours": [
"RecordEvidence",
"Builtin",
"AssetCreator",
],
"attributes": {
"genre": "Soul",
"stage_name": "Adele",
"arc_description": "British Soul Singer",
"arc_display_name": "Adele Laurie Blue Adkins",
"arc_display_type": "Artists",
"arc_primary_image": {
"arc_blob_identity": "blobs/a39ed534-d1b3-4b23-84e0-01a2cceea9a2",
"arc_display_name": "arc_primary_image",
"arc_file_name": "pexels-andrea-turner-707697.jpeg",
"arc_attribute_type": "arc_attachment",
"arc_blob_hash_alg": "SHA256",
"arc_blob_hash_value": "cf0dd630dcfb6e2eac65c362bf7d5ff382a4241ebf45a69a2541ee43320d4af6"
},
"artistid": "989130159"
},
"confirmation_status": "CONFIRMED",
"tracked": "TRACKED",
"owner": "0x5284e740A744F075E402f7fB0c4485532ddf4Af8",
"at_time": "2023-06-02T21:33:34Z",
"storage_integrity": "TENANT_STORAGE",
"chain_id": "8275868384",
"public": false,
"tenant_identity": "tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1"
}
[9]:
# Create two Events that contain album release information for existing Artist
print("Creating Events for existing Asset")
event_one = create_release(arch, asset, album_name="25", release="2015")
print("Event for Album 25", json_dumps(event_one, indent=4))
event_two = create_release(arch, asset, album_name="30", release="2021")
print("Event for Album 30", json_dumps(event_two, indent=4))
Creating Events for existing Asset
Event for Album 25 {
"identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f/events/90c34f0f-79c5-41c9-9ff7-76deaaaa4f64",
"asset_identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f",
"event_attributes": {
"relase_year": "2015",
"album_name": "25",
"arc_description": "Artist Information for existing Artist",
"arc_display_type": "Album Release for existing Artist"
},
"asset_attributes": {},
"operation": "Record",
"behaviour": "RecordEvidence",
"timestamp_declared": "2023-06-02T21:33:40Z",
"timestamp_accepted": "2023-06-02T21:33:40Z",
"timestamp_committed": "2023-06-02T21:33:40.813694893Z",
"principal_declared": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "43a271b9-5b25-4740-aa9f-1cbd51ed3625",
"display_name": "mwilder26",
"email": ""
},
"principal_accepted": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "43a271b9-5b25-4740-aa9f-1cbd51ed3625",
"display_name": "mwilder26",
"email": ""
},
"confirmation_status": "CONFIRMED",
"transaction_id": "",
"block_number": 0,
"transaction_index": 0,
"from": "0x5284e740A744F075E402f7fB0c4485532ddf4Af8",
"tenant_identity": "tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1"
}
Event for Album 30 {
"identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f/events/69145272-d3a8-4590-810c-49a6419d8fc0",
"asset_identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f",
"event_attributes": {
"arc_display_type": "Album Release for existing Artist",
"relase_year": "2021",
"album_name": "30",
"arc_description": "Artist Information for existing Artist"
},
"asset_attributes": {},
"operation": "Record",
"behaviour": "RecordEvidence",
"timestamp_declared": "2023-06-02T21:33:42Z",
"timestamp_accepted": "2023-06-02T21:33:42Z",
"timestamp_committed": "2023-06-02T21:33:42.205724430Z",
"principal_declared": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "43a271b9-5b25-4740-aa9f-1cbd51ed3625",
"display_name": "mwilder26",
"email": ""
},
"principal_accepted": {
"issuer": "https://app.datatrails.ai/appidpv1",
"subject": "43a271b9-5b25-4740-aa9f-1cbd51ed3625",
"display_name": "mwilder26",
"email": ""
},
"confirmation_status": "CONFIRMED",
"transaction_id": "",
"block_number": 0,
"transaction_index": 0,
"from": "0x5284e740A744F075E402f7fB0c4485532ddf4Af8",
"tenant_identity": "tenant/0a62f7c9-fd7b-4791-8041-01218d839ec1"
}