Ejemplo n.º 1
0
def rate_specific_movie(user_id):
	print
	movie_id_to_rate = int(raw_input("Please enter the movie ID# for the movie you wish to rate. "))
	already_rated = int(IIDH.database_query("SELECT count(rating) FROM ratings WHERE user = {0} AND movie = {1}".format(user_id, movie_id_to_rate))[0][0])

	if already_rated > 0:
		user_answer = raw_input("You have already rated this movie. Do you wish to edit your rating?")
		if user_answer == "yes":
			edit_existing_movie(user_id)
		else:
			main_menu(user_id)

	movie_title_to_rate = IIDH.database_query("SELECT title FROM movies WHERE id = {0}".format(int(movie_id_to_rate)))[0][0]

	print("The movie you chose is {0}".format(movie_title_to_rate))
	user_answer = raw_input("Is this the movie you want to rate?")
	if user_answer == "no":
		rate_specific_movie(user_id)
	elif user_answer == "yes":
		user_rating = raw_input("Please rate {0} on a scale from 1 to 5.".format(movie_title_to_rate))
		IIDH.database_write("INSERT INTO ratings (user, movie, rating, timestamp) VALUES ({0}, {1}, {2}, {3})".format(user_id, movie_id_to_rate, int(user_rating), int(time.time())))
	print "Thank you for your rating."
	user_answer = raw_input("Would you like to rate another movie?")
	if user_answer == "yes":
		rate_specific_movie(user_id)
	else:
		main_menu(user_id)
Ejemplo n.º 2
0
def new_user():
	user_id = int(IIDH.database_query("SELECT max(id) FROM users")[0][0]) + 1
	print("Your user ID is {0}. Please write it down.".format(user_id))
	print("Please answer the following demographic questions. ")
	user_age = raw_input("What is your age? ")
	user_sex = raw_input("What is your gender M/F? ")
	user_prof = raw_input("What is your profession? ")
	user_zip = raw_input("What is your zipcode? ")
	IIDH.database_write("INSERT INTO users (id, age, sex, profession, zipcode) VALUES ({0}, {1}, '{2}', '{3}', {4})".format(user_id, int(user_age), user_sex, user_prof, int(user_zip)))
	answer = raw_input("Before making recommendations, we'll need you to rate some movies. \nPlease rate at least 20 of the following movies to increase accuracy.")
	rate_random_movies(user_id)
Ejemplo n.º 3
0
def edit_existing_movie(user_id):
	print
	movie_id_to_edit = int(raw_input("What is the ID# of the movie you wish to edit?"))
	movie_title_to_edit = IIDH.database_query("SELECT title FROM movies WHERE id = {0}".format(movie_id_to_edit))[0][0]
	current_rating = int(IIDH.database_query("SELECT rating FROM ratings WHERE user = {0} AND movie = {1}".format(user_id, movie_id_to_edit))[0][0])
	print("Your current rating for {0} is {1}/5".format(movie_title_to_edit, current_rating))
	answer = raw_input("Do you want to change this?")
	if answer == "yes":
		new_rating = raw_input("What would you like to rate {0} from 1 to 5.".format(movie_title_to_edit))
		IIDH.database_write("UPDATE ratings SET rating = {0} where user = {1} AND movie = {2}".format(new_rating, user_id, movie_id_to_edit))
		main_menu(user_id)
	else:
		main_menu(user_id)
Ejemplo n.º 4
0
def rate_random_movies(user_id):
	print("Please rate the following movies. \nType 'done' to end this rating session. ")
	movie_count = IIDH.get_movie_count()
	already_rated = set(sum(IIDH.database_query("SELECT movie FROM ratings WHERE user = {0}".format(user_id)), ()))
	all_movies = set(sum(IIDH.database_query("SELECT id FROM movies"), ()))
	random_movie_list = all_movies - already_rated
	shuffled_movie_list = list(random_movie_list)
	random.shuffle(shuffled_movie_list)
	print(random_movie_list)
	print(shuffled_movie_list)
	for movie_id in shuffled_movie_list:
		movie_title = IIDH.database_query("SELECT title FROM movies WHERE id={0}".format(movie_id))[0][0]
		user_answer = raw_input("Have you seen {0} {1}? ".format(movie_id, movie_title))
		if user_answer == "no":
			pass
		elif user_answer == "done":
			main_menu(user_id)
		else:
			user_rating = raw_input("Please rate {0} from 1 to 5. ".format(movie_title))
			IIDH.database_write("INSERT INTO ratings (user, movie, rating, timestamp) VALUES ({0}, {1}, {2}, {3})".format(user_id, movie_id, int(user_rating), int(time.time())))
	main_menu(user_id)