def stats(self): query_directors = select(['persons.id', func.count('roles.person_id').label('count')], from_obj=['persons', 'roles'], whereclause="roles.person_id = persons.id AND roles.role_type = 'director'", group_by=['persons.id'], order_by='count desc', limit=10) query_actors = select(['persons.id', func.count('roles.person_id').label('count')], from_obj=['persons', 'roles'], whereclause="roles.person_id = persons.id AND roles.role_type = 'cast'", group_by=['persons.id'], order_by='count desc', limit=10) top_directors = DBSession.query(Person, 'count').from_statement(query_directors).all() top_actors = DBSession.query(Person, 'count').from_statement(query_actors).all() ia = IMDb() top250_ids = [x.movieID for x in ia.get_top250_movies()] bottom100_ids = [x.movieID for x in ia.get_bottom100_movies()] top250_count = DBSession.query(Movie).filter(Movie.id.in_(top250_ids)).count() bottom100_count = DBSession.query(Movie).filter(Movie.id.in_(bottom100_ids)).count() total_count = DBSession.query(Movie).count() total_runtime = 1 return {'top250_count': top250_count, 'bottom100_count': bottom100_count, 'total_count': total_count, 'total_runtime' : total_runtime, 'top_directors': top_directors, 'top_actors': top_actors}
class ImdbApi(): def __init__(self): self.ia = IMDb() def get_top_movies(self): return self.ia.get_top250_movies() def get_bottom_movies(self): return self.ia.get_bottom100_movies() def get_movies_id(self, movies): return [i.getID() for i in movies] def list_of_filtered_movie_information(self, movies_id): l = [] for i in movies_id[:10]: di = {} film = self.ia.get_movie_main(i) di['rating'] = [i[1] for i in film['data'].items() if i[0] == 'rating'] di['year'] = [i[1] for i in film['data'].items() if i[0] == 'year'] di['name'] = [i[1] for i in film['data'].items() if i[0] == 'title'] di['director'] = [i[1] for i in film['data'].items() if i[0] == 'director'][0][0] di['index'] = random.randint(0, 9) l.append(di) return l
def get_bottom_movies(args): connection = IMDb() items = connection.get_bottom100_movies() if args.first: connection.update(items[0]) print(items[0].summary()) else: list_ranking(items, n=args.n)
person = db.get_person(actor_id) bio = db.get_person_biography(actor_id) name = person['name'] bdate = person['birth date'] height = person['height'] trivia = person['trivia'] titleRefs = bio['titlesRefs'] print(f'name: {name}') print(f'birth date: {bdate}') print(f'height: {height}') print(f'trivia: {trivia[0]}') titleRefs = ', '.join(map(str, titleRefs)) print(f'bio title refs: {titleRefs}') print('---------------------------------------') # 4) Fetch top/bottom 10 movies top = db.get_top250_movies() bottom = db.get_bottom100_movies() print('Top 10 movies are:') for movie in top[0:9]: print(movie) print() print('Bottom 10 movies are:') for movie in bottom[0:9]: print(movie)
for searches in search_return: if re.search( movie_title, searches ): # from the api's searched movie list, find the one that matches our title exactly movie_and_ids.append(searches) movie_ids = [] movie_names = [] for info in movie_and_ids: # from our matched result, we only need the title and id number movie_names.append(re.sub("_", "", (re.search(r"_.*_", info)).group())) movie_ids.append(re.search("\d{7}", info).group()) # getting imdb's own movies lists top_250 = ia.get_top250_movies() bottom_100 = ia.get_bottom100_movies() # adding the titles and ids from imdb's list to our scraped list above for x in top_250: if x.movieID not in movie_ids: movie_ids.append(x.movieID) movie_names.append(x['title']) for x in bottom_100: if x.movieID not in movie_ids: movie_ids.append(x.movieID) movie_names.append(x['title']) #creating a dictionary of our database data_base = dict(zip(movie_names, movie_ids))
import googleapiclient.errors from src.common.Database import Database from src.model.Movie import Movie from src.model.User import User import requests from bs4 import BeautifulSoup from werkzeug.utils import redirect import random from flask_share import Share movielist = [] moviesDB = IMDb() search = moviesDB.get_top250_movies() search1 = moviesDB.get_top250_indian_movies() search2 = moviesDB.get_popular100_tv() search3 = moviesDB.get_bottom100_movies() for m in search1: movielist.append(m.getID()) for i in movielist: movieurl = "https://www.imdb.com/title/tt" + i + "/" r = requests.get(url=movieurl) soup = BeautifulSoup(r.text, 'html.parser') try: title = soup.find('title') ratingValue = soup.find("span", {"itemprop": "ratingValue"}) image = soup.find("div", {"class": "poster"}).find("img")["src"] link = soup.find("div", {"class": "slate"}).find("a")["href"] genre = soup.find("div", {"class": "subtext"}).find("a") if link != None and image != None and title != None and ratingValue != None: dm = Movie(title.string, "bollywood", genre.text,