Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ChatBotGroup/imdbrating.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (33 sloc)
1.45 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from imdb import IMDb | |
import random | |
ia = IMDb() | |
# IMDbPY documentation was used. | |
# https://imdbpy.sourceforge.io/support.html and https://github.com/alberanid/imdbpy/tree/master/docs/usage | |
def randomMovieTop250(): | |
"""Returns random movie from top 250. Takes no input""" | |
top250 = ia.get_top250_movies() # Variable top 250 is used to store movies from top 250 from IMDBpy | |
r = random.randint(0, 250) | |
randomMovie = top250[r] | |
return randomMovie | |
def movieRating(movieName): | |
"""Returns rating of selected film and gives an opinion by taking the movie name""" | |
movielist = ia.search_movie(movieName) | |
firstinlist = movielist[0] | |
ia.update(firstinlist) | |
try: | |
if firstinlist['rating'] >= 8: | |
botrating = "It's excellent!" | |
elif 7.1 <= firstinlist['rating'] < 8: | |
botrating = "It's really good." | |
elif 6 <= firstinlist['rating'] < 7.1: | |
botrating = "It's okay." | |
elif 4 <= firstinlist['rating'] < 6: | |
botrating = "It's bad." | |
elif 2 <= firstinlist['rating'] < 4: | |
botrating = "It's really bad!" | |
else: | |
botrating = ("It's unwatchable! You should look for any other movie.\n" + | |
"Try watching " + str(randomMovieTop250())) | |
return ("%s is rated %s" % (firstinlist['title'], firstinlist['rating'])+ "\n" + str(botrating)) | |
except: | |
return ("I don't think that there is any movie called " + movieName) |