campaign/queries.py
def recommended_songs(indexes, distances, cur):

    """ This function will take in index values and then return 
        a list of song and artist names"""

    # Queries the database 
    query = "SELECT name, artists FROM target WHERE index IN ("
    first = True
    for index in indexes[0][1:]:
      if first == False:
        query = query + ', ' + str(index)
      else:
        first = False
        query = query + str(index)
    query = query + ")"

    # Creates the dataframe
    data = {'name':[], 'artists':[], 'distances': distances[0][1:]}
    cur.execute(query)
    records = cur.fetchall()
    for record in records:
      data['name'].append(record[0])
      data['artists'].append(record[1])
    
    recommendations = pd.DataFrame(data)

    return recommendations
 This function will take in index values and then return 
        a list of song and artist names
This function will take in index values and then return
a list of song and artist names
This function will take in index values and then return a list of song and artist names
def recommended_songs(indexes, distances, cur):
    query = "SELECT name, artists FROM target WHERE index IN ("
    first = True
    for index in indexes[0][1:]:
      if first == False:
        query = query + ', ' + str(index)
      else:
        first = False
        query = query + str(index)
    query = query + ")"
    data = {'name':[], 'artists':[], 'distances': distances[0][1:]}
    cur.execute(query)
    records = cur.fetchall()
    for record in records:
      data['name'].append(record[0])
      data['artists'].append(record[1])
    recommendations = pd.DataFrame(data)
    return recommendations
def recommended_songs ( indexes , distances , cur ) : query = "SELECT name, artists FROM target WHERE index IN (" first = True for index in indexes [ 0 ] [ 1 : ] : if first == False : query = query + ', ' + str ( index ) else : first = False query = query + str ( index ) query = query + ")" data = { 'name' : [ ] , 'artists' : [ ] , 'distances' : distances [ 0 ] [ 1 : ] } cur . execute ( query ) records = cur . fetchall ( ) for record in records : data [ 'name' ] . append ( record [ 0 ] ) data [ 'artists' ] . append ( record [ 1 ] ) recommendations = pd . DataFrame ( data ) return recommendations
This function will take in index values and then return
a list of song and artist names
This function will take in index values and then return a list of song and artist names
""" This function will take in index values and then return 
        a list of song and artist names""" # Queries the database  # Creates the dataframe
indexes
distances
cur