Skip to content

Commit 24b48c1

Browse files
committed
Minor tweak
1 parent 725581e commit 24b48c1

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

moviebox/data.py

+16
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ def splitData(moviesDF, verbose):
3636
return {'titles': titles, 'categories': categories, 'plots': plots}
3737

3838

39+
def validateInput(movieID, recommendationsNumber):
40+
# Check whether the input ID is valid
41+
if not (isinstance(movieID, int) and movieID >= 0 and movieID <= 4999):
42+
printRed('Invalid value for movie ID: "' + str(movieID) + '"')
43+
printRed('Input is not a valid Natural number between [0, 4999]')
44+
sys.exit(1)
45+
# Check whether the recommendations number is valid
46+
if not (isinstance(recommendationsNumber, int)
47+
and recommendationsNumber >= 1 and recommendationsNumber <= 30):
48+
printRed('Invalid value for recommendations number: "' +
49+
str(recommendationsNumber) + '"')
50+
printRed('Input is not a valid Natural number between [1, 30]')
51+
sys.exit(1)
52+
return 0
53+
54+
3955
def searchMovie(movieID):
4056
# Search a movie title by ID
4157
data = importData(verbose=False)

moviebox/output.py

-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import re
2-
import sys
32

43
from colorama import init
54
from termcolor import colored
@@ -67,20 +66,6 @@ def prettyPrint(movieID, title, category, plot, color, showPlots):
6766
print(colored(' Plot:\n' + plot + '\n', color))
6867

6968

70-
def validateInput(movieID, recommendationsNumber):
71-
if not (isinstance(movieID, int) and movieID >= 0 and movieID <= 4999):
72-
printRed('Invalid value for movie ID: "' + str(movieID) + '"')
73-
printRed('Input is not a valid Natural number between [0, 4999]')
74-
sys.exit(1)
75-
if not (isinstance(recommendationsNumber, int)
76-
and recommendationsNumber >= 1 and recommendationsNumber <= 30):
77-
printRed('Invalid value for recommendations number: "' +
78-
str(recommendationsNumber) + '"')
79-
printRed('Input is not a valid Natural number between [1, 30]')
80-
sys.exit(1)
81-
return 0
82-
83-
8469
def displayHelpMessage():
8570
# Display cli help message
8671
print(helpMessage)

moviebox/recommender.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from .data import importData, splitData
1+
from .data import importData, splitData, validateInput
22
from .tfidf import trainEngine, getSimilarities
3-
from .output import printYellow, printGreen, prettyPrint, validateInput
3+
from .output import printYellow, printGreen, prettyPrint
44

55
green = 'green' # Green colored text
66
yellow = 'yellow' # Yellow-colored text

0 commit comments

Comments
 (0)