Exemplo n.º 1
0
def refresh_list():
	'''
	This is the function that interfaces with
	Ajax/JavaScript inside output.html.

	Here, we take the following steps:
	```````````````````````````````````
	1. Wait for information from the user on
	   what he/she did not like. 
	2. Call the python algorithm for re-ranking
	   best musicians for the user.
	'''
	# store the jsonified data from the app's user
	out_dict = request.json
	# get the rejected artists
	rejected_artists = request.json['rejected_artists']
	# currently upvoted_artists are not used
	upvoted_artists = request.json['upvoted_artists']
	# store the root artist
	root_artist = request.json['root_artist']

	# make sure we don't have any unicode characters
	# that will disrupt our string comparisons in 
	# get_artist_recs()
	if type(rejected_artists) is list:
		for i in range( len(rejected_artists) ):
			rejected_artists[i] = rejected_artists[i].replace(
				'&', '&')

	# pass to recommendation algorithm
	rec = get_artist_recs(root_artist, drop_names = rejected_artists,
		                  upvote_names = upvoted_artists
		                  )

	# store the names and screen names of rec'd artists
	rec_name = rec['name']
	rec_sn   = rec['sn']

	# concatenate these recommendations
	rec = rec_name + rec_sn
	print rec[:]
	
	# store in a dict to the json file
	# for passing back to the web-browser.
	data = {}
	for i, v in enumerate( rec ):
		data[i] = v

	return jsonify(data)
Exemplo n.º 2
0
def api_output():
	'''
	This is the function that interfaces with
	Ajax/JavaScript inside output.html.

	Here, we take the following steps:
	```````````````````````````````````
	1. Call the python algorithm for ranking
	   best musicians for the user given root artist.
	'''
	# get the root artist
	artist = request.args['artist']
	
	# Call the backend algorithm to get best
	# initial recommendations from stored twitter data.
	rec = get_artist_recs( artist.strip() )
	rec_name = rec['name']
	rec_sn   = rec['sn']

	# now render the HTML for output
	return render_template('output.html', recommendation=rec_name,
		rec_sn = rec_sn, root_artist = artist)