Create Artist and Album Release Info

[1]:
# Create an Asset with corresponding Events
#
# Main function, establishes a connection to DataTrails using an App Registration then uses that
# to create an Asset with 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]:
import random
import string

from json import dumps as json_dumps
from os import getenv
from warnings import filterwarnings

from dotenv import load_dotenv

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("No value for DATATRAILS_UNIQUE_ID")
[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 create_artist(arch, name, artist_name, genre, artistid):
    """
    Creates an Asset that passes name, stage name, music genre and unique id
    for an Artist
    """
    attrs = {
        "arc_display_name": name,
        "arc_description": "British Soul Singer",
        "arc_display_type": "Artists",
        "stage_name": artist_name,
        "genre": genre,
        "artistid": artistid,
    }

    return arch.assets.create(attrs=attrs)
[7]:
def create_release(arch, asset, album_name, release):
    """
    Creates an Event that passes album name and release year
    """
    props = {"operation": "Record", "behaviour": "RecordEvidence"}
    attrs = {
        "arc_description": "Artist Information",
        "arc_display_type": "Album Release",
        "album_name": album_name,
        "relase_year": release,
    }

    return arch.events.create(asset["identity"], props=props, attrs=attrs)
[8]:
# Creating an Asset for musical artist Adele
print("Creating Asset")
asset = create_artist(
    arch,
    name="Adele Laurie Blue Adkins",
    artist_name="Adele",
    genre="Soul",
    artistid=DATATRAILS_UNIQUE_ID,
)
print("Asset", json_dumps(asset, indent=4))
Creating Asset
Refresh token
Asset {
    "identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f",
    "behaviours": [
        "RecordEvidence",
        "Builtin",
        "AssetCreator"
    ],
    "attributes": {
        "arc_display_name": "Adele Laurie Blue Adkins",
        "arc_display_type": "Artists",
        "artistid": "989130159",
        "genre": "Soul",
        "stage_name": "Adele",
        "arc_description": "British Soul Singer"
    },
    "confirmation_status": "CONFIRMED",
    "tracked": "TRACKED",
    "owner": "0x5284e740A744F075E402f7fB0c4485532ddf4Af8",
    "at_time": "2023-06-02T20:57:01Z",
    "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 Adele
print("Creating Events")
event_one = create_release(arch, asset, album_name="19", release="2008")
print("Event for Album 19", json_dumps(event_one, indent=4))
event_two = create_release(arch, asset, album_name="21", release="2011")
print("Event for Album 21", json_dumps(event_two, indent=4))
Creating Events
Event for Album 19 {
    "identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f/events/7dcd25e1-e469-4fe8-9cae-6e467dbc35b9",
    "asset_identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f",
    "event_attributes": {
        "relase_year": "2008",
        "album_name": "19",
        "arc_description": "Artist Information",
        "arc_display_type": "Album Release"
    },
    "asset_attributes": {},
    "operation": "Record",
    "behaviour": "RecordEvidence",
    "timestamp_declared": "2023-06-02T20:57:08Z",
    "timestamp_accepted": "2023-06-02T20:57:08Z",
    "timestamp_committed": "2023-06-02T20:57:08.267262759Z",
    "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 21 {
    "identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f/events/5119ae7d-658a-4b6c-98c6-0a3ab99b487b",
    "asset_identity": "assets/17a59a16-3d5c-4d58-8ea6-1b86465ff32f",
    "event_attributes": {
        "relase_year": "2011",
        "album_name": "21",
        "arc_description": "Artist Information",
        "arc_display_type": "Album Release"
    },
    "asset_attributes": {},
    "operation": "Record",
    "behaviour": "RecordEvidence",
    "timestamp_declared": "2023-06-02T20:57:10Z",
    "timestamp_accepted": "2023-06-02T20:57:10Z",
    "timestamp_committed": "2023-06-02T20:57:10.089205082Z",
    "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"
}