Beispiel #1
0
def analyze():
    
    #DEBUG
    app.logger.warning(request.get_json())
    app.logger.warning(type(request.get_json()))
    app.logger.warning(request.get_json()['artist'])

    # retrieve artist from request
    artist = request.get_json()['artist'].lower()

    # get artist id
    artist_id = (song_retrieval.get_artist_id(artist))

    app.logger.warning(artist_id)
    # check if the artist is already in the database
    if database.check_artist(artist_id):
        # if so, retrieve data and return
        artist_stats = database.get_artist(artist_id)
        return json.dumps(artist_stats)

    # otherwise run analytics
    song_retrieval.perform_analytics(int(artist_id), artist)

    artist_stats = database.get_artist(artist_id)
    return json.dumps(artist_stats)
Beispiel #2
0
def single_artist(artist_id):
    """
    Show a single artist by artist_id in your media server
    Can do this without a login
    """
    # # Check if the user is logged in, if not: back to login.
    # if('logged_in' not in session or not session['logged_in']):
    #     return redirect(url_for('login'))
    global allmovies
    global alltvshows
    page['title'] = 'Artist ID: '+artist_id

    # Get a list of all artist by artist_id from the database
    artist = None
    artist = database.get_artist(artist_id)

    # Data integrity checks
    if artist == None:
        artist = []


    # Data integrity checks
    if allmovies == None:
        allmovies = []
    
    if alltvshows == None:
        alltvshows == []

    return render_template('singleitems/artist.html',
                           session=session,
                           page=page,
                           user=user_details,
                           artist=artist,
                           allmovies = allmovies,
                           alltvshows=alltvshows)
Beispiel #3
0
def single_artist(artist_id):
    """
    Show a single artist by artist_id in your media server
    Can do this without a login
    """
    # # Check if the user is logged in, if not: back to login.
    # if('logged_in' not in session or not session['logged_in']):
    #     return redirect(url_for('login'))

    page['title'] = 'Artist ID: ' + artist_id

    # Get a list of all artist by artist_id from the database
    artist = None
    artist = database.get_artist(artist_id)

    # Data integrity checks
    if artist == None:
        artist = []
    if (request.method == 'POST'):
        print(artist)
        try:
            fave = artist.fave
            if (fave == 1):
                database.add_fave_artist(artist_id, 0)
            else:
                database.add_fave_artist(artist_id, 1)
        except:
            print("YAY")
            database.add_fave_artist(artist_id, 1)
    return render_template('singleitems/artist.html',
                           session=session,
                           page=page,
                           user=user_details,
                           artist=artist)
Beispiel #4
0
def add_song():
    """
    Add a new Song
    """
    # # Check if the user is logged in, if not: back to login.
    if('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))

    #########
    # TODO  #
    #########

    #############################################################################
    # Fill in the Function below with to do all data handling for adding a song #
    #############################################################################

    page['title'] = 'Add Song' # Add the title

    songs = None
    print("request form is:")
    newdict = {}
    print(request.form)

    if request.method == 'POST':
        # Set up some variables to manage the post returns

        #Once retrieved, do some data integrity checks on the data
        # if (songs == None or songs == []):
        #     songs=[]
        #     page['bar'] == False #这个对吗
        #     flash("")
        if ('song_title' not in request.form):
            newdict['song_title'] = 'Empty song title Value'
        else:
            newdict['song_title'] = request.form['song_title']
            print("We have a value: ",newdict['song_title'])

        if ('songlength' not in request.form):
            newdict['songlength'] = '0'
        else:
            newdict['songlength'] = request.form['songlength']
            print("We have a value: ",newdict['songlength'])

        if ('songdescription' not in request.form):
            newdict['songdescription'] = 'Empty description field'
        else:
            newdict['songdescription'] = request.form['songdescription']
            print("We have a value: ",newdict['songdescription'])

        if ('storage_location' not in request.form):
            newdict['storage_location'] = 'Empty storage location'
        else:
            newdict['storage_location'] = request.form['storage_location']
            print("We have a value: ",newdict['storage_location'])

        if ('song_genre' not in request.form):
            newdict['song_genre'] = 'random'
        else:
            newdict['song_genre'] = request.form['song_genre']
            print("We have a value: ",newdict['song_genre'])

        if ('artwork' not in request.form):
            newdict['artwork'] = 'https://user-images.githubusercontent.com/24848110/33519396-7e56363c-d79d-11e7-969b-09782f5ccbab.png'
        else:
            newdict['artwork'] = request.form['artwork']
            print("We have a value: ",newdict['artwork'])
        
        if ('artist_id' not in request.form):
            return render_template('createitems/createsong.html',
                           session=session,
                           page=page,
                           user=user_details)
        else:

            id = request.form['artist_id']
            if (database.get_artist(id) == None or database.get_artist(id) == []):
                return render_template('createitems/createsong.html',
                           session=session,
                           page=page,
                           user=user_details)
            else:
                newdict['artist_id'] = id
                print("We have a value: ",newdict['artist_id'])

        print('newdict is:')
        print(newdict)

        # Once verified, send the appropriate data to the database for insertion
        songs = database.add_song_to_db(newdict['storage_location'],newdict['songdescription'],newdict['song_title'],newdict['songlength'],newdict['song_genre'],newdict['artist_id'],newdict['artwork'])

        # NOTE :: YOU WILL NEED TO MODIFY THIS TO PASS THE APPROPRIATE VARIABLES
        max_song_id = database.get_last_song()[0]['song_id']
        return single_song(max_song_id)
    else:
        return render_template('createitems/createsong.html',
                           session=session,
                           page=page,
                           user=user_details)
Beispiel #5
0
def add_song():
    """
    Add a new Song
    """
    # # Check if the user is logged in, if not: back to login.
    if ('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))

    #########
    # TODO  #
    #########

    #############################################################################
    # Fill in the Function below with to do all data handling for adding a song #
    #############################################################################

    page['title'] = 'Song  Creation'  # Add the title
    newdict = {}

    if request.method == 'POST':

        if ('song_title' not in request.form):
            newdict['song_title'] = 'Empty Film Value'
        else:
            newdict['song_title'] = request.form['song_title']
            print("We have a value: ", newdict['song_title'])

        if ('songLength' not in request.form):
            newdict['songLength'] = '0'
        else:
            newdict['songLength'] = request.form['songLength']
            print("We have a value: ", newdict['songLength'])

        if ('description' not in request.form):
            newdict['description'] = 'Empty description field'
        else:
            newdict['description'] = request.form['description']
            print("We have a value: ", newdict['description'])

        if ('storage_location' not in request.form):
            newdict['storage_location'] = 'Empty storage location'
        else:
            newdict['storage_location'] = request.form['storage_location']
            print("We have a value: ", newdict['storage_location'])

        if ('song_genre' not in request.form):
            newdict['song_genre'] = 'pop'
        else:
            newdict['song_genre'] = request.form['song_genre']
            print("We have a value: ", newdict['song_genre'])

        if ('artistid' not in request.form):
            newdict['artistid'] = 'Empty artist_id'
        else:
            newdict['artistid'] = request.form['artistid']
            print("We have a value: ", newdict['artistid'])

        try:
            if int(newdict['songLength']) <= 0:
                raise Exception("invalid length")
            int(newdict['artistid'])
            artist = database.get_artist(newdict['artistid'])
            if not artist or len(artist) < 1:
                raise Exception("invalid artistid")
        except:
            flash("Invalid input for new song.")
            return render_template('createitems/createsong.html',
                                   session=session,
                                   page=page,
                                   user=user_details)

        songs = None
        songs = database.add_song_to_db(newdict['storage_location'],
                                        newdict['description'],
                                        newdict['song_title'],
                                        newdict['songLength'],
                                        newdict['song_genre'],
                                        newdict['artistid'])

        max_song_id = database.get_last_song()[0]['song_id']
        print(songs)
        print(max_song_id)

        if songs is not None:
            max_song_id = songs[0]

        return single_song(max_song_id)
        # Set up some variables to manage the post returns

        # Once retrieved, do some data integrity checks on the data

        # Once verified, send the appropriate data to the database for insertion

        # NOTE :: YOU WILL NEED TO MODIFY THIS TO PASS THE APPROPRIATE VARIABLES
        return render_template('singleitems/song.html',
                               session=session,
                               page=page,
                               user=user_details,
                               songs=songs)
    else:
        return render_template('createitems/createsong.html',
                               session=session,
                               page=page,
                               user=user_details)
Beispiel #6
0
def add_song():
    """
    Add a new Song
    """
    # # Check if the user is logged in, if not: back to login.
    if('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))

    #########
    # TODO  #
    #########

    #############################################################################
    # Fill in the Function below with to do all data handling for adding a song #
    #############################################################################

    page['title'] = 'Song Creation' # Add the title

    songs = None
    print("request form is:")
    newdict = {}
    print(request.form)

    # Retrieve all existing artists to pass into createsong.html
    artists = None
    artists = database.get_allartists()

    # Data integrity checks
    if artists == None:
        artists = []
    else:
        # Order artist_id by ascending order for readability
        artists = sorted(artists, key = lambda k: k['artist_id'])

    if request.method == 'POST':
        # Set up some variables to manage the post returns

        # Once retrieved, do some data integrity checks on the data
        if ('song_title' not in request.form):
            newdict['song_title'] = 'Empty song'
        else:
            newdict['song_title'] = request.form['song_title']
            print("We have a value: ",newdict['song_title'])

        if ('song_length' not in request.form):
            newdict['song_length'] = '0'
        else:
            newdict['song_length'] = request.form['song_length']
            print("We have a value: ",newdict['song_length'])

        if ('storage_location' not in request.form):
            newdict['storage_location'] = 'No location'
        else:
            newdict['storage_location'] = request.form['storage_location']
            print("We have a value: ",newdict['storage_location'])

        if ('artist_id' not in request.form):
            newdict['artist_id'] = '1'
        else:
            newdict['artist_id'] = request.form['artist_id']
            print("We have a value: ",newdict['artist_id'])

        if ('description' not in request.form):
            newdict['description'] = 'No description'
        else:
            newdict['description'] = request.form['description']
            print("We have a value: ",newdict['description'])

        if ('song_genre' not in request.form):
            newdict['song_genre'] = 'pop'
        else:
            newdict['song_genre'] = request.form['song_genre']
            print("We have a value: ",newdict['song_genre'])

        if ('artwork' not in request.form):
            newdict['artwork'] = 'https://user-images.githubusercontent.com/24848110/33519396-7e56363c-d79d-11e7-969b-09782f5ccbab.png'
        else:
            newdict['artwork'] = request.form['artwork']
            print("We have a value: ",newdict['artwork'])

        print('newdict is:')
        print(newdict)

        # Once verified, send the appropriate data to the database for insertion
        matching_artists = database.get_artist(newdict['artist_id'])
        if len(matching_artists) > 0:
            songs = database.add_song_to_db(newdict['storage_location'],newdict['description'],newdict['song_title'],newdict['song_length'],newdict['song_genre'],newdict['artist_id'])

        # Latest song is most recently added song to database
        # only if the new song cannot be inserted
        latest_song_id = database.get_last_song()[0]['song_id']
        print("printing songs: {}".format(songs))
        if songs is not None:
            latest_song_id = songs[0]

        return single_song(latest_song_id)
    else:
        return render_template('createitems/createsong.html',
                           session=session,
                           page=page,
                           user=user_details,
                           artists=artists)