def get_ratings(title="Game of Thrones"): try: # check if we already have the ratings of the listing data = np.load("data/{}.npy".format(title.lower())) print("Loaded data from disk") return data, title except: client = OMDBClient(apikey="cc71ac81") client.set_default("tomatoes", True) # ratings for season 1 xml_content = client.get(title=title, season=1) num_episodes = len(xml_content["episodes"]) # total number of seasons total_seasons = int(xml_content["total_seasons"]) print("Total seasons: {}".format(total_seasons)) list = [] listoflists = [] for item in xml_content["episodes"]: list.append(item["imdb_rating"]) listoflists.append(list) print(listoflists) # get the ratings of other seasons for i in range(2, total_seasons + 1): list = [] xml_content = client.get(title=title, season=i) for item in xml_content["episodes"]: list.append(item["imdb_rating"]) listoflists.append(list) print(listoflists) maxlen = 0 for item in listoflists: if len(item) > maxlen: maxlen = len(item) for item in listoflists: while len(item) < maxlen: item.append(None) data = np.array(listoflists).transpose() np.place(data, data == "N/A", None) print(data) data = data.astype(np.float) print("Loaded data from omdb") np.save("data/{}".format(title.lower()), data) return data, title
def omdb_data(arguments): movie_name, year = arguments client = OMDBClient(apikey=OMDB_API_KEY) try: result = client.get(title=movie_name, year=year, fullplot=True, tomatoes=True) except HTTPError as e: print(e) client.set_default("apikey", OMDB_API_KEY_fallback) result = client.get(title=movie_name, year=year, fullplot=True, tomatoes=True) result_to_keep = {} for key in requested_flat_fields: result_to_keep[key] = result.get(key, None) for nested_field in requested_nested_fields: requested_nested_list = requested_nested_fields[nested_field] nested_list = result.get(nested_field, None) if nested_list: for nested_dict in nested_list: source = nested_dict.get("source", None) if source: value = nested_dict.get("value", None) if source in requested_nested_list: source_formatted = to_snake_case(source) key = f"{nested_field}_{source_formatted}" result_to_keep[key] = value requested_sources = requested_nested_fields[nested_field] for requested_source in requested_sources: source_formatted = to_snake_case(requested_source) key = f"{nested_field}_{source_formatted}" if not key in result_to_keep: result_to_keep[key] = None else: requested_sources = requested_nested_fields[nested_field] for requested_source in requested_sources: source_formatted = to_snake_case(requested_source) key = f"{nested_field}_{source_formatted}" result_to_keep[key] = None return t.Row(*list(result_to_keep.keys()))(*list(result_to_keep.values()))
def _get_omdb_data(self): for rec in self: # Get OMDB Data try: from omdb import OMDBClient client = OMDBClient(apikey=rec.api_key.name) items = [] if client: for i in range(1, rec.pages + 1): page_items = client.get( media_type=rec.type_id.name, search=rec.name, year=rec.year if rec.year else None, season=rec.season if rec.season else None, episode=rec.episode if rec.episode else None, fullplot=rec.fullplot, tomatoes=rec.tomatoes, timeout=rec.timeout, page=i) if page_items: items += page_items return items except: raise UserError( "There are Issue When Connect With OMDB Api and Get Data.")
def get_data(title="Game of Thrones"): client = OMDBClient(apikey="cc71ac81") client.set_default("tomatoes", True) xml_content = client.get(title=title) response = requests.get(xml_content["poster"]) img = Image.open(BytesIO(response.content)) img.save("static/{}.png".format(title.lower()), format="png") return xml_content
def emoji_ratings(self) -> Dict[str, str]: global omdb if omdb is None: omdb = OMDBClient(apikey=settings.OMDB_API_KEY) id, title = self.id, None if self.id else self.title movie = omdb.get(imdbid=id, title=title) if movie: ratings = movie.get("ratings") e_ratings = reduce(emojify_sources, ratings, {}) return e_ratings
def get_api_data(self, movie_id): """ Get API data for movie :param movie_id: imdb id """ client = OMDBClient(apikey=self.api_key) movie_info = client.get(imdbid=movie_id) # Download and store poster movie_poster_url = movie_info['poster'] urllib.urlretrieve(movie_poster_url, "pepper_html/imdb/images/movie_poster.jpg") self.movie_data = movie_info
def generate_poster_url_dict(imdb_ids): """ :param imdb_ids: list of movie ids :return: list of urls to corresponding posters. """ client = OMDBClient(apikey=os.environ.get('OMDB_API_KEY')) poster_url_list = [] for imdb_id in imdb_ids: data = client.get(imdbid=imdb_id) poster_url = data['poster'] print(poster_url) poster_url_list.append(poster_url) return poster_url_list
def search_movie(): ''' Searches for a movie to add to the list ''' form = SearchForMovie() if form.validate_on_submit(): results = [] client = OMDBClient(apikey=Omdb.OMDB_KEY) search = client.search_movie(form.search.data) for s in search: title = s['title'] year = s['year'] movie = client.get(title=title, year=year, fullplot=False) results.append(movie) return render_template('search.html', results=results, form=form) return render_template('search.html', form=form)
def membersearchmovie(request, type_id, user_id): movietitle = request.GET.get('movietitle') if not movietitle: return render(request, 'error/error.html') movie = models.movie.objects.filter(title=movietitle) if not movie: API_KEY = '66a8c2f3' client = OMDBClient(apikey=API_KEY) movie_data = client.get(movietitle) allmovie = [] for movie in movie_data: new_movie = Imdb_Movie(title=movie['title'], poster=movie['poster'], watchlink="https://www.imdb.com/title/" + movie['imdb_id']) allmovie.append(new_movie) cd = {'allmovie': allmovie} return render(request, 'error/error2.html', cd) else: moviefound = models.movie.objects.get(title=movietitle) return HttpResponseRedirect('/movie/' + str(moviefound.id) + '/type/' + str(type_id) + '/id/' + str(user_id) + '/')
def get_movie(title): client = OMDBClient(apikey=omdb_key) response = client.get(title=title, timeout=5, tomatoes='true') return response