Skip to content
Permalink
Browse files
Create Searchmoviewithtitles.py
  • Loading branch information
bakkaredds committed Nov 26, 2021
1 parent 3adde4f commit ae14a3d2a0e3597d2558197d5c6d6c46a010a4fe
Showing 1 changed file with 57 additions and 0 deletions.
@@ -0,0 +1,57 @@
import csv
import math
import re
import sys

from random import randint

def movie_title_str(self, search_str):
matches = []
min_edit_length = float('inf')

for movie_index in xrange(0, len(self.titles)):
movie = self.titles[movie_index]
# rearrange title to put articles in front
title = str.lower(self.rearrange_articles(movie[0]))
if search_str == title:
return movie_index
else:
if search_str in title: # check if search_str is a substring of title
edit_length = self.edit_length(title, search_str)
if edit_length < min_edit_length:
matches = [movie_index] + matches
if len(matches) > 10:
matches = matches[0:10]
min_edit_length = edit_length
else:
if len(matches) < 10:
matches.append(movie_index)

if len(matches) > 1:
index = -1
for i in xrange(0, len(matches)):
print ("str(i) + ': ' + self.titles[matches[i]][0] + '\n'")

while index < 0 or index > len(matches):
input_str = raw_input('Did you mean one of these movies ? Please select the index of the movie you meant + \ or enter "none" if none of them are what you are looking for: ')
if input_str == "none"
return -2

try:
index = int(input_str)
if index < 0 or index > len(matches):
print ("Please enter \'none\' or a valid number from the above indices.")
except ValueError:
print ("Please enter \'none\' or a valid number from the above indices.")
except NameError:
print ("Please enter \'none\' or a valid number from the above indices.")
except SyntaxError:
print ("Please enter \'none\' or a valid number from the above indices.")

return matches[index]

elif len(matches) == 1:
return matches[0]
else:
return -1

0 comments on commit ae14a3d

Please sign in to comment.