コード例 #1
0
ファイル: admin.py プロジェクト: davidwmartines/trogs
def create_artist(artistName, owner='', bio='', imageUrl=''):
    table = db.get_table()

    id = ids.new_id()

    print("creating '{0}', id '{1}'".format(artistName, id))

    table.put_item(
        Item={
            'PK': id,
            'SK': id,
            'AA_SK': artistName,
            'Owner': owner,
            'AA_PK': 'ARTISTS',
            'AC_PK': id,
            'AC_SK': '000',
            'Bio': bio,
            'ImageURL': imageUrl,
            'NormalizedName': safe_obj_name(artistName),
            'CreatedDate': datetime.datetime.utcnow().isoformat(
                timespec='seconds')
        })

    query = table.query(IndexName="IX_ARTISTS_ALBUMS",
                        KeyConditionExpression=Key('AA_PK').eq('ARTISTS')
                        & Key('AA_SK').eq(artistName))

    print(query["Items"][0])

    return id
コード例 #2
0
ファイル: admin.py プロジェクト: davidwmartines/trogs
def create_album(artistName,
                 albumTitle,
                 releaseDateISO,
                 license,
                 description='',
                 imageUrl='',
                 ac_sort=None):
    table = db.get_table()

    res = table.query(IndexName='IX_ARTISTS_ALBUMS',
                      KeyConditionExpression=Key('AA_PK').eq('ARTISTS')
                      & Key('AA_SK').eq(artistName))

    if len(res['Items']) == 0:
        print("Error: No artist found named '{0}'.".format(artistName))
        return

    artist = res['Items'][0]
    print(artist)

    id = ids.new_id()

    if ac_sort is None:
        res = table.query(IndexName='IX_ARTIST_CONTENT',
                          ScanIndexForward=True,
                          KeyConditionExpression=Key('AC_PK').eq(artist['PK'])
                          & Key('AC_SK').begins_with('2'))

        if len(res['Items']) > 0:
            last_item = res['Items'][len(res['Items']) - 1]
            last_sort = int(last_item['AC_SK'])
            ac_sort = str(last_sort + 1)
        else:
            ac_sort = '200'

    print("creating '{0}', id '{1}', sort {2}".format(albumTitle, id, ac_sort))

    table.put_item(
        Item={
            'PK': artist['PK'],
            'AA_PK': id,
            'AA_SK': '000',
            'AC_PK': artist['PK'],
            'AC_SK': ac_sort,
            'ReleaseDate': releaseDateISO,
            'AlbumTitle': albumTitle,
            'SK': id,
            'PK': artist['PK'],
            'ArtistName': artist['AA_SK'],
            'Description': description,
            'License': license,
            'ImageURL': imageUrl
        })

    query = table.query(IndexName="IX_ARTISTS_ALBUMS",
                        KeyConditionExpression=Key('AA_PK').eq(id))

    print(query["Items"][0])

    return id
コード例 #3
0
def add_artist_normalized_names():

    table = db.get_table()

    response = table.query(
        IndexName='IX_ARTISTS_ALBUMS',
        ScanIndexForward=True,
        KeyConditionExpression=Key('AA_PK').eq('ARTISTS'),
        ProjectionExpression='PK, SK, AA_SK, NormalizedName')

    for item in response['Items']:

        normalized_name = item.get('NormalizedName')
        if normalized_name:
            print('"{0}" already has "{1}"'.format(item['AA_SK'],
                                                   normalized_name))
        else:
            normalized_name = names.safe_obj_name(item['AA_SK'])
            print('setting "{0}" to "{1}"'.format(item['AA_SK'],
                                                  normalized_name))
            table.update_item(
                Key={
                    'PK': item['PK'],
                    'SK': item['SK']
                },
                UpdateExpression='set NormalizedName = :normalized_name',
                ExpressionAttributeValues={
                    ':normalized_name': normalized_name
                },
                ReturnValues='UPDATED_NEW')
コード例 #4
0
ファイル: admin.py プロジェクト: davidwmartines/trogs
def add_single(artistName,
               trackTitle,
               audioUrl,
               releaseDataISO,
               license,
               sortNum=None):
    table = db.get_table()

    res = table.query(IndexName='IX_ARTISTS_ALBUMS',
                      KeyConditionExpression=Key('AA_PK').eq('ARTISTS')
                      & Key('AA_SK').eq(artistName))

    if len(res['Items']) == 0:
        print("Error: No artist found named '{0}'.".format(artistName))
        return

    artist = res['Items'][0]

    print(artist)

    if sortNum is None:
        res = table.query(IndexName='IX_ARTIST_CONTENT',
                          ScanIndexForward=True,
                          KeyConditionExpression=Key('AC_PK').eq(artist['PK'])
                          & Key('AC_SK').begins_with('3'))
        if len(res['Items']) > 0:
            last_track = res['Items'][len(res['Items']) - 1]
            last_sort = int(last_track['AC_SK'])
            sort = str(last_sort + 1)
        else:
            sort = '300'
    else:
        sort = str(sortNum)

    id = ids.new_id()

    print("creating '{0}', id '{1}', sort {2}".format(trackTitle, id, sort))

    table.put_item(
        Item={
            'PK': id,
            'SK': id,
            'AC_PK': artist['PK'],
            'AC_SK': sort,
            'TrackTitle': trackTitle,
            'AudioURL': audioUrl,
            'ArtistID': artist['PK'],
            'ArtistName': artist['AA_SK'],
            'License': license,
            'ReleaseDate': releaseDataISO
        })

    res = table.query(KeyConditionExpression=Key('PK').eq(id))

    print(res["Items"][0])

    return id
コード例 #5
0
def add_feature_sort():

    table = db.get_table()
    # for each artist
    response = table.query(IndexName='IX_ARTISTS_ALBUMS',
                           ScanIndexForward=True,
                           KeyConditionExpression=Key('AA_PK').eq('ARTISTS'),
                           ProjectionExpression='PK, AA_SK')

    for item in response['Items']:
        artist_id = item['PK']
        print('checking artist {0}'.format(item['AA_SK']))
        # get featured tracks
        content = table.query(
            IndexName='IX_ARTIST_CONTENT',
            ScanIndexForward=True,
            KeyConditionExpression=Key('AC_PK').eq(artist_id))
        featured = list(
            filter(lambda i: bool(i.get('Featured', False)), content['Items']))
        print('found {0} featured tracks'.format(len(featured)))
        for track_item in featured:
            if not 'FeatureSort' in track_item:
                print('adding feature sort to {0}'.format(
                    track_item['TrackTitle']))
                #set FeatureSort = existing AC_SK
                feature_sort = track_item['AC_SK']
                content_sort = None
                if not 'AA_PK' in track_item:
                    print('setting single back to proper AC_SK')
                    res = table.query(
                        IndexName='IX_ARTIST_CONTENT',
                        ScanIndexForward=True,
                        KeyConditionExpression=Key('AC_PK').eq(artist_id)
                        & Key('AC_SK').begins_with('3'))
                    content_sort = '300'
                    if len(res['Items']) > 0:
                        last = res['Items'][-1]
                        last_sort = int(last['AC_SK'])
                        content_sort = str(last_sort + 1)

            print('setting featuresort to {0} and content_sort to {1}'.format(
                feature_sort, content_sort))
            update_exp = 'set FeatureSort = :feature_sort'
            update_exp_vals = {':feature_sort': feature_sort}
            if content_sort is not None:
                update_exp += ', AC_SK = :content_sort'
                update_exp_vals[':content_sort'] = content_sort

            table.update_item(Key={
                'PK': track_item['PK'],
                'SK': track_item['SK']
            },
                              UpdateExpression=update_exp,
                              ExpressionAttributeValues=update_exp_vals)
コード例 #6
0
ファイル: admin.py プロジェクト: davidwmartines/trogs
def feature_track(id):

    table = db.get_table()

    # get track
    res = table.query(KeyConditionExpression=Key('PK').eq(id)
                      & Key('SK').eq(id))
    if len(res['Items']) == 0:
        print('no track found by id', id)
        return
    track = res['Items'][0]

    # determine feature sort
    sort = '100'
    res = table.query(IndexName='IX_ARTIST_CONTENT',
                      ScanIndexForward=True,
                      KeyConditionExpression=Key('AC_PK').eq(track['ArtistID'])
                      & Key('AC_SK').begins_with('1'))
    if len(res['Items']) > 0:
        last_track = res['Items'][len(res['Items']) - 1]
        last_sort = int(last_track['AC_SK'])
        sort = str(last_sort + 1)

    # define update
    update_exp = 'set AC_PK = :AC_PK, Featured = :Featured, FeatureSort = :FeatureSort'
    update_exp_vals = {
        ':AC_PK': track['ArtistID'],
        ':Featured': True,
        ':FeatureSort': sort
    }

    if 'AC_SK' not in track:
        update_exp += ', AC_SK = :AC_SK'
        update_exp_vals[':AC_SK'] = sort

    # update
    res = table.update_item(Key={
        'PK': id,
        'SK': id
    },
                            UpdateExpression=update_exp,
                            ExpressionAttributeValues=update_exp_vals,
                            ReturnValues='UPDATED_NEW')

    print(res)
コード例 #7
0
ファイル: admin.py プロジェクト: davidwmartines/trogs
def add_track(artistName, albumTitle, trackTitle, audioUrl, sortNum=None):
    table = db.get_table()

    res = table.query(IndexName='IX_ARTISTS_ALBUMS',
                      KeyConditionExpression=Key('AA_PK').eq('ARTISTS')
                      & Key('AA_SK').eq(artistName))

    if len(res['Items']) == 0:
        print("Error: No artist found named '{0}'.".format(artistName))
        return

    artist = res['Items'][0]

    print(artist)

    res = table.query(IndexName='IX_ARTIST_CONTENT',
                      ScanIndexForward=True,
                      KeyConditionExpression=Key('AC_PK').eq(artist['PK'])
                      & Key('AC_SK').begins_with('2'))

    albums = list(
        filter(lambda item: attr_matches('AlbumTitle', albumTitle, item),
               res['Items']))

    if len(albums) == 0:
        print("Error: No album found by '{0}' with title '{1}'.".format(
            artist["ArtistName"], albumTitle))
        return

    album = albums[0]

    print(album)

    if sortNum is None:
        res = table.query(
            IndexName='IX_ARTISTS_ALBUMS',
            ScanIndexForward=True,
            KeyConditionExpression=Key('AA_PK').eq(album['AA_PK'])
            & Key('AA_SK').begins_with('1'))

        if len(res['Items']) > 0:
            last_track = res['Items'][len(res['Items']) - 1]
            last_sort = int(last_track['AA_SK'])
            sort = str(last_sort + 1)
        else:
            sort = '100'
    else:
        sort = str(sortNum)

    id = ids.new_id()

    print("creating '{0}', id '{1}', sort {2}".format(trackTitle, id, sort))

    table.put_item(
        Item={
            'PK': id,
            'SK': id,
            'AA_PK': album['AA_PK'],
            'AA_SK': sort,
            'TrackTitle': trackTitle,
            'AudioURL': audioUrl,
            'AlbumTitle': albumTitle,
            'ArtistID': album['PK'],
            'ArtistName': album['ArtistName'],
            'License': album['License']
        })

    res = table.query(KeyConditionExpression=Key('PK').eq(id))

    print(res["Items"][0])

    return id