def create(self, validated_data): movie = Movie.objects.create( name=validated_data['name'], description=omdb.get(title=validated_data['name'])['type'], year=omdb.get(title=validated_data['name'])['year'], released=omdb.get(title=validated_data['name'])['year'], rating=omdb.get(title=validated_data['name'])['imdb_rating']) movie.save() return movie
def search_movie_with_title(title, year=None): if pd.isna(year) == False: movie = omdb.get(title=title, year=year, fullplot=True, tomatoes=True) else: movie = omdb.get(title=title, fullplot=True, tomatoes=True) if movie: return movie else: return {}
def test_get(): result = omdb.get(title='True Grit') assert result['title'] == 'True Grit' result = omdb.get(imdbid='tt0065126') assert result['imdb_id'] == 'tt0065126' results = omdb.get(search='True Grit') assert results[0]['title'] == 'True Grit'
def main(): # include full plot and Rotten Tomatoes data a = omdb.get(title='True Grit', year=1969, fullplot=True, tomatoes=True) # set timeout of 5 seconds for this request b = omdb.get(title='True Grit', year=1969, fullplot=True, tomatoes=True, timeout=5) return a, b
def receive(title, kind, season=None, episode=None): name = ' '.join([ str(title), str(kind) if kind else 'video', str('S%s' % season) if season else '', str('E%s' % episode) if episode else '' ]).strip() try: data = omdbcache.get(name) if data: return data if omdbcache.ignored(name): logging.info("OMDB fetch '%s' ignored", name) return data if not key: logging.info("OMDB fetch '%s' skipped; KEY not set", name) return data logging.info("OMDB fetch '%s' new data", name) data = omdb.get(title=title, media_type=kind, season=season, episode=episode) if verify(data): omdbcache.set(data, name) return data omdbcache.miss(name) logging.warning("OMDB fetch '%s' responded: %s", name, data) except Exception as e: logging.warning("OMDB fetch '%s' failed: %s", name, e)
def search_filename(fname, fields): """Retrieve movie infos from filename. """ path_tokens = os.path.normpath(fname).split(os.sep) for candidate in (path_tokens[-1], path_tokens[-2]): res = re.split(FNAME_SPLIT_RE, candidate, flags=re.I | re.U)[0].strip() res = scrub(res, '[({])}', ' ') res = ' '.join([x for x in re.split(r'[\s\._]', res, flags=re.U) if x]) years = re.findall(r'((?:19|20)\d\d)', res) if years: toks = re.split(r'(%s)' % years[-1], res) else: toks = [res] title = unidecode(toks[0].strip()) year = toks[1] if len(toks) > 1 else None query = {'fullplot': False, 'tomatoes': False, 'title': title} if year: query['year'] = year if (title, year) in CACHED_RESULTS: item = CACHED_RESULTS[(title, year)] else: item = omdb.get(**query) if item: for f in fields: format_field(item, f) CACHED_RESULTS[(title, year)] = item if item: item['filename'] = fname return item
def request(item): try: movie = omdb.get(title=item[0], year=item[1], tomatoes=True) except Exception as e: print e, "caused by", item[0] return None if str(movie) != "Item({})": mtitle = movie.title myear = movie.year critscore = movie.tomato_meter conscore = movie.tomato_user_meter mid = movie.imdb_id med_type =movie.type runtime = movie.runtime metascore= movie.metascore lang = movie.language released = movie.released imdb_rating = movie.imdb_rating imdb_votes = movie.imdb_votes box_office = movie.box_office country = movie.country if str(critscore) != "N/A": return mid + " ||| " + mtitle + " ||| " + myear + " ||| " + critscore + " ||| " + conscore + mid + " ||| " + med_type + " ||| " + runtime + " ||| " + metascore + " ||| " + lang + " ||| " + released + " ||| " + imdb_rating + " ||| " + imdb_votes + " ||| " + box_office + " ||| " + country + " ||| " + "\n" else: return None
def test_search_series(self): t = 'True Grit' media_type = 'series' self.assertEqual(omdb.search_series(t)[0].type, media_type) self.assertEqual(omdb.get(title=t, media_type=media_type).type, media_type)
def test_search_episode(self): t = 'True Grit' media_type = 'episode' self.assertEqual(omdb.search_episode(t)[0].type, media_type) self.assertEqual(omdb.get(title=t, media_type=media_type).type, media_type)
def get_movie(): cnx = mysql.connector.connect( user='******', password='******', host='qbct6vwi8q648mrn.cbetxkdyhwsb.us-east-1.rds.amazonaws.com', database='itpo6r2v2r37o2w2') cursor = cnx.cursor(dictionary=True) jsonresponse = '[' i = 0 while i < 10: movieName = "" while (movieName == ""): id = random.randrange(2, 2569) query = ("SELECT * FROM movies WHERE table_id=%s") cursor.execute(query, (id, )) for row in cursor: movieName = row["title"] response = omdb.get(title=movieName) if "metascore" in response: if response["metascore"] != "N/A": score = response["metascore"] poster = response["poster"] movieInfo = '{"name":"' + movieName + '","poster":"' + poster + '","score":' + score + '}' i += 1 jsonresponse += movieInfo if (i < 10): jsonresponse += ',' cursor.close() cnx.close() jsonresponse += ']' return jsonresponse
def getSimMatrix(title): movie = omdb.get(title=title) if movie: #set index to be title movieDF = pd.DataFrame() fullTitle = movie['title'] movieDF = movieDF.append({'Title': movie['title'], 'Genre' : movie['genre'], 'Director' : movie['director'], 'Actors' : movie['actors'], 'Plot' : movie['plot']}, ignore_index=True) df = pd.read_csv("https://query.data.world/s/uikepcpffyo2nhig52xxeevdialfl7") df = df[['Title','Genre','Director','Actors','Plot']] df = df.append(movieDF, sort=False) df.set_index('Title', inplace=True) df['Key_words'] = "" for index,row in df.iterrows(): plot = row['Plot'].lower() r = Rake() #extract keywords form plot r.extract_keywords_from_text(plot); #add list of keywords as column keyWords = list(r.get_ranked_phrases()) for word in keyWords: word.replace(" ", "") word.lower() row['Key_words'] = " ".join(keyWords) row['Director'] = row['Director'].lower().replace(" ", "").replace(",", " ") row['Actors'] = row['Actors'].lower().replace(" ", "").replace(",", " ") row['Genre'] = row['Genre'].lower().replace(",", "") #drop plot column df.drop(['Plot'], axis=1) #bag of words, words from all columns df['bagOfWords'] = df['Genre'] + " " + df['Director'] + " " +\ df['Actors'] + " " + df['Key_words'] #drop all columns but bagOfWords df.drop(df.columns[:-1], axis=1, inplace=True) count = CountVectorizer() count_matrix = count.fit_transform(df['bagOfWords']) similarity = cosine_similarity(count_matrix, count_matrix) #index to movie title return pd.Series(df.index), similarity, fullTitle else: return None, None, "Could not find movie"
def test_search_episode(self): t = 'True Grit' media_type = 'episode' self.assertEqual(omdb.search_episode(t)[0].type, media_type) self.assertEqual( omdb.get(title=t, media_type=media_type).type, media_type)
def getOMDB(title, year, season, episode, imdbid, ver=None): try: if Prefs["use_debug"]: Log("OMDB Request: Title:%s Year:%s Season:%s Episode:%s imdb:%s" % (title, year, season, episode, imdbid)) c = 0 res = None while res == None and c < 3: try: res = omdb.get(title=title, year=int(year), season=str(season), episode=str(episode), imdbid=imdbid, c=Prefs['ca_api_key'], ver=ver, timeout=10) except Exception as e: c += 1 time.sleep(1.0) return res except Exception as e: Log("interface.py>requestOMDB() >> : >>> %s" % (e)) return None
def picture(self): omdb.set_default('apikey', 'c69d8944') res = omdb.get(title=self._name, year=self._year) if "poster" in res.keys(): return res["poster"] else: return None
def test_search_series(self): t = 'True Grit' media_type = 'series' self.assertEqual(omdb.search_series(t)[0].type, media_type) self.assertEqual( omdb.get(title=t, media_type=media_type).type, media_type)
def index(): current_date = str(datetime.now()) tmdb.API_KEY = "27591dafb389ecb4d7c7bb206fbfe833" movie_6 = {} top_6 = tmdb.Discover() movie_list = [] response = top_6.movie(page = 1, sort_by = "popularity.desc", year=2015) #Loop through results from The Movie Database site and set titles into an array for a future call i = 0 while i < 6: movie_list.append(top_6.results[i]['title']) i = i +1 #Takes titles from The Movie Database and uses the Open Movie database to get further info for m in movie_list: movie_info = omdb.get(title=m, fullplot=True, tomatoes=True) url_clean = movie_info["poster"] imdb_clean = movie_info["imdb_id"] imdb_id = re.sub(r'tt',"",imdb_clean) # trailers = requests.get('http://api.traileraddict.com/?imdb='+imdb_id+'&count=1&width=680') poster_image_url = re.sub(r'(^\[)\w|(\])+g',"",url_clean) movie_6.update({m:movies.Movie(m,[movie_info["plot"]],poster_image_url,imdb_id)}) return render_template('index.html', movie_tiles = movie_6)
def movies(request, movie_id): connection = connections['default'] cursor = connection.cursor() cursor.execute('SELECT id, title, original_title, vote_average FROM ' 'movie WHERE id = (%s);', (movie_id,)) movie_data = dictfetchall(cursor)[0] cursor.execute('SELECT DISTINCT g.name FROM ' '(((SELECT * FROM movie WHERE id = (%s)) m ' 'INNER JOIN movie_genre mg ON (mg.movie_id = m.id)) ' 'INNER JOIN genre g ON (g.id = mg.genre_id));', (movie_id,)) template = loader.get_template('movies/movie.html') genres = '' for genre in dictfetchall(cursor): genres += genre['name'] + ', ' genres = genres[:-2] context = RequestContext(request, { 'genres': genres, 'movie': movie_data, 'plot': omdb.get(title = movie_data['title'], fullplot = True)['plot'], }) return HttpResponse(template.render(context))
def datos_peli_imbd(self, titulo=None, idFicha=None, anio=None, sinopsis=None, titulo_es=None): logger.debug('-------------- BUSCAMOS EN IMBD --------------------') vapikey = 'c3ca59d0' omdb.set_default('apikey', vapikey) pelicula = [] if titulo == None and idFicha == None: logger.error("No hay parámetros para la busqueda") pelicula = [] elif idFicha <> None: pelicula = omdb.imdbid(idFicha) elif titulo <> None: if anio == None: pelicula = omdb.get(title=titulo) else: pelicula = omdb.get(title=titulo, year=anio) if pelicula: log_datos(pelicula) item = { 'titulo': titulo_es, 'titulo_orig': pelicula.title, 'anio': pelicula.year, 'generos': pelicula.genre, 'imagen': pelicula.poster, 'pais': pelicula.country, 'escritor': pelicula.writer, 'director': pelicula.director, 'actores': pelicula.actors, 'duracion': pelicula.runtime, 'sinopsis': pelicula.plot, 'sinopsis_es': sinopsis, 'idFicha': 'Imdb-' + pelicula.imdb_id, } logger.debug('Finalmente nos queda ') log_datos(item) else: return None return item
def validate_name(self, value): data = omdb.get(title=value) if data: print(data['title']) return value else: raise serializers.ValidationError("Film not Found")
def get_episodes_in_season(title, season): episodes_json = omdb.get(title=title, season=season)["episodes"] episodes = [] for ej in episodes_json: episodes.append( make_episode(ej["title"], ej["released"], season, ej["episode"], ej["imdb_rating"])) return episodes
def imdb_search(movie_name): try: search = omdb.search(movie_name) first_match = search[0].title rating = omdb.get(title=first_match, tomatoes=True) return float(rating['imdb_rating']) except: return 0
def add_film(film_list=[]): """" Takes a list of tuples ex. films = [ (film_title, file_path_for_film) ] """ # for film in film_list: film_json_obj = omdb.get(title=film[0], fullplot=True, tomatoes=True) #print film_json_obj # Check if film was actually received, if not skip to next film if film_json_obj.get('response') is None: print "FAILED. Was not able to retrieve film for via omdb api. Please check the title." continue # Convert all attributes for a film to unicode. for att in film_json_obj: film_json_obj[att] = film_json_obj[att].encode("utf-8").strip() filmmodel = Film.objects.get_or_create(title=film_json_obj.get('title'))[0] filmmodel.year = film_json_obj.get('year') filmmodel.rated = film_json_obj.get('rated') filmmodel.released = film_json_obj.get('released') filmmodel.runtime = film_json_obj.get('runtime') filmmodel.type = film_json_obj.get('type') filmmodel.award = film_json_obj.get('award') filmmodel.plot = film_json_obj.get('plot') filmmodel.poster = film_json_obj.get('poster') filmmodel.imdb_id = film_json_obj.get('imdb_id') filmmodel.imdb_rating = film_json_obj.get('imdb_rating') filmmodel.meta_score = film_json_obj.get('meta_score') filmmodel.file_path = film[1] for l in film_json_obj.get('language').strip().split(","): new_language = Language.objects.get_or_create(language_name=l)[0] filmmodel.language.add(new_language) for g in film_json_obj.get('genre').strip().split(","): new_genre = Genre.objects.get_or_create(name=g)[0] filmmodel.genre.add(new_genre) for c in film_json_obj.get('country').strip().split(","): new_country = Country.objects.get_or_create(country_name=c)[0] filmmodel.country.add(new_country) for a in film_json_obj.get('actors').strip().split(","): new_actor = Actor.objects.get_or_create(full_name=a)[0] filmmodel.actor.add(new_actor) for d in film_json_obj.get('director').strip().split(","): new_director = Director.objects.get_or_create(full_name=d)[0] filmmodel.director.add(new_director) for w in film_json_obj.get('writer').strip().split(","): new_writer = Writer.objects.get_or_create(full_name=w)[0] filmmodel.writer.add(new_writer) filmmodel.save() print "Adding film....", filmmodel.title, filmmodel.year
def get_all_episodes(title): show_info = omdb.get(title=title) num_seasons = int(show_info["total_seasons"]) episodes = [] season = 1 while season <= num_seasons: episodes.extend(get_episodes_in_season(title, season)) season += 1 return episodes
def test_search_series(): t = 'Game of Thrones' media_type = 'series' results = omdb.search_series(t) assert results[0]['type'] == media_type result = omdb.get(title=t, media_type=media_type) assert result['type'] == media_type
def test_search_movie(): t = 'True Grit' media_type = 'movie' results = omdb.search_movie(t) assert results[0]['type'] == media_type result = omdb.get(title=t, media_type=media_type) assert result['type'] == media_type
def movie_list(request): ''' diplays list of movies as main body (search on side)''' try: movies = Movie.objects.all().order_by('title') #if movies: # paginations if to show only five movies per page paginator = Paginator(movies, 5) page = request.GET.get('page') try: movies = paginator.page(page) except PageNotAnInteger: movies = paginator.page(1) except EmptyPage: movies = paginator.page(paginator.num_pages) # except ProgrammingError: # print("4") # movies = None if request.method == "POST": form = SearchForm(request.POST) msg = None if form.is_valid(): movie = form.save(commit=False) details = omdb.get(title=movie.title) if details: movie.year = details['year'] movie.length = details['runtime'] try: movie.save() messages.add_message(request, messages.SUCCESS, "Movie added") print("movie saved to db") except: messages.add_message(request, messages.INFO, "Unable to save") print("not saved") else: msg = "Movie not found, maybe you can't spell for doo-doo." movies = Movie.objects.all().order_by('title') return render(request, 'movies/list.html', {'movies':movies, 'form':form, 'msg':msg, 'page':page,}) else: form = SearchForm() return render(request, 'movies/list.html', {'movies':movies, 'form':form, 'page':page,}) except TypeError: # no movies in db , movies=>None form = SearchForm() return render(request, 'movies/list.html', {'form':form})
def update_movie(): for movie in sess.query(Movie).filter(Movie.rating > 0).all(): omdbSearch = omdb.get(imdbid=movie.movie_id, fullplot=True) if omdbSearch.runtime != 'N/A': rtime = omdbSearch.runtime rtime = int(strip_numb(rtime)) print rtime else: rtime = None movie.time = rtime sess.commit()
def api_request(item): movie = omdb.get(title=item[0], year=item[1], tomatoes=True) if str(movie) != "Item({})": mtitle = movie.title myear = movie.year critscore = movie.tomato_meter conscore = movie.tomato_user_meter mid = movie.imdb_id if str(critscore) != "N/A": return (mid, mtitle, myear, critscore, conscore) else: return None
def movie_api(form): title = form.cleaned_data['title'] year = form.cleaned_data['year'] genre = form.cleaned_data['genre'] if title: if year: movie = [] movie.append(omdb.get(title=title, year=year)) return movie else: return omdb.search_movie(title)
def get_tv_meta(episode): imdb = omdb.get(imdbid=episode['imdb_id']) meta = AttrDict( title = episode['episodename'], actors = imdb['actors'], year = imdb['year'], plot = episode['overview'], genre = imdb['genre'], ) return meta
def scrape(t, y): x = omdb.get(title= t, year=y, fullplot=True, tomatoes=False) if x: plot = x['plot'] age = x['rated'] poster = x['poster'] imdbid = x['imdb_id'] genre = x['genre'] language = x['language'] return '%s; %s; %d; %s; %s; %s' % (imdbid, t, y, genre, age, poster) else: pass
def scrape(t, y): x = omdb.get(title=t, year=y, fullplot=True, tomatoes=False) if x: plot = x['plot'] age = x['rated'] poster = x['poster'] imdbid = x['imdb_id'] genre = x['genre'] language = x['language'] return '%s; %s; %d; %s; %s; %s' % (imdbid, t, y, genre, age, poster) else: pass
def test_search_episode(): t = 'A' media_type = 'episode' results = omdb.search_episode(t) # FIXME: OMDb API is no longer returning results for this query. Have # been unable to find an actual type=episode query that returns # results. Skip test if no results found until a replacement query can # be found. if results: assert results[0]['type'] == media_type assert omdb.get(title=t, media_type=media_type)['type'] == media_type
def get_movie(movie, movies): ''' Send request with movie title to imdb API :param movie: title of movie which we are looking for inside imdb :param movies: list of dictionaries to store movie details returned by imdb API :return: None ''' movie_stats = omdb.get(title=movie) # send request to imdb API for given title if movie_stats and movie_stats not in movies: # if dictionary is not empty and is not in list of dictionaries movies.append(movie_stats) # add it to the list return None
def querymovie(*args, **kwargs): title = kwargs.get('title', '') year = kwargs.get('year', '') imdbid = kwargs.get('imdbid', None) #print '###querymovie###',title, year, imdbid #comments if title: title = title.replace('.',' ') omdb.set_default('tomatoes','true') omdb.set_default('plot','full') if imdbid <> None: res = omdb.get(imdbid=imdbid) else: res = omdb.get(title=title,year=year) #print res # comment if len(res)>0: return res elif title: return searchmovie(title, year) else: return ''
def get_movie_info(s): unique_key = "omdb_{}".format(s) if unique_key in CACHE_DICT["MOVIE_DICT"]: print("Using cached omdb data for", s) pass else: print("Getting new data from omdb for", s) movie_data = omdb.get(title=s, fullplot=False, tomatoes=True) CACHE_DICT["MOVIE_DICT"][unique_key] = movie_data fileref = open(CACHE_FILE, "w") fileref.write(json.dumps(CACHE_DICT)) fileref.close() return CACHE_DICT["MOVIE_DICT"][unique_key]
def media_database_builder(file, API_KEY, start_index, stop_index): """ This function used requests imdb movies and tv information using the omdb module and appends them to a dataframe INPUTS: file = file containing imdb keys API Key Start index and Stop index for imdb keys OUTPUTS: Excel csv spreadsheet containing information """ # convert unique imdb title to dataframe col_name = ['imdbid'] imdb_id = pd.read_csv(file, sep='\t', names=col_name) omdb.set_default('apikey', API_KEY) client = OMDBClient(apikey=API_KEY) rows_list = [] for i in range(int(start_index), int(stop_index)): print(i) movie_ID = imdb_id.iloc[i, 0] try: movie_dict = omdb.get(imdbid=movie_ID) rows_list.append(movie_dict) # Generates HTTP Error r = omdb.request(imdbid=movie_ID) # Value error - imdb ID yeilds dictionary that is empty # HTTPError (522) - Exceeded requests per unit time # Timeout - Overrules default timeout value except (ValueError, requests.HTTPError, requests.ReadTimeout) as err: if err == ValueError: continue else: i = i - 1 time.sleep(2.0) print('Error has occured') print('Retry request in 2.0 seconds') continue media_df = pd.DataFrame(rows_list) media_csv = media_df.to_csv(r'media_data.csv', mode='a', header=False, index=None, encoding="utf-8") return media_csv
def movies(bot,message,title): chat_id=message.chat_id #makes the imdb search url if match not found def buildImdbUrl(title): title_list = [element.strip() for element in title.split(' ')] url_elements = [ 'http://www.imdb.com/find?ref_=nv_sr_fn&q=', '+'.join(title_list), '&s=all' ] url = ''.join(url_elements) logging.info('imdb url built',url) return url #poll api try: result = omdb.get(title=title) result.title except: sendText(bot,message.chat_id,msgs['nomovie']) bot.sendMessage(chat_id=chat_id,text=buildImdbUrl(title),disable_web_page_preview=True) #sendText(bot,message.chat_id,str(buildImdbUrl(title)),True) else: logging.info('omdb result:', result) film = result.title year = result.year director = result.director metascore = result.metascore imdbscore = result.imdb_rating plot = result.plot poster = result.poster imdb = 'http://www.imdb.com/title/'+result.imdb_id #exception handling for movies with no poster try: bot.sendPhoto(chat_id=chat_id,photo=poster) except: logging.error("no poster found in omdb result",result) reply = ( 'Title: '+film+'\n' 'Year: '+year+'\n' 'Director: '+director+'\n' 'Metascore: '+metascore+'\n' 'IMDb rating: '+imdbscore+'\n' 'Plot:\n'+plot ) sendText(bot,chat_id,reply) sendText(bot,chat_id,imdb,True)
def test_search_episode(self): t = 'True Grit' media_type = 'episode' results = omdb.search_episode(t) # FIXME: OMDb API is no longer returning results for this query. Have # been unable to find an actual type=episode query that returns # results. Skip test if no results found until a replacement query can # be found. if results: self.assertEqual(results[0].type, media_type) self.assertEqual(omdb.get(title=t, media_type=media_type).type, media_type)
def test_search_episode(self): t = 'True Grit' media_type = 'episode' results = omdb.search_episode(t) # FIXME: OMDb API is no longer returning results for this query. Have # been unable to find an actual type=episode query that returns # results. Skip test if no results found until a replacement query can # be found. if results: self.assertEqual(results[0].type, media_type) self.assertEqual( omdb.get(title=t, media_type=media_type).type, media_type)
def createMoviesDatabase(userInput): movies = [] titleNames = userInput.split(' : ')[0] try: sortBy = userInput.split(' : ')[1] except: sortBy = '' for title in titleNames.split(', '): movie = omdb.get(title=title) if len(movie) == 0: print(f"Nie znaleziono {title} w bazie.") else: movies.append(movie) return movies, sortBy
def add_poster_link(self, movie: Movie): omdb.set_default('apikey', 'b03ac630') query_result = omdb.get(title=movie.title, year=movie.year, fullplot=True, tomatoes=True) try: poster_link = query_result['poster'] if poster_link is not None and poster_link != "": movie.poster_link = poster_link else: movie.poster_link = '/static/blankimg.jpg' except: movie.poster_link = '/static/blankimg.jpg'
def format(data, mtitle, count): if(count < 3): place = str("top") else: place = str("next") embed = discord.Embed(Title="IMDb Search", description="Here are the "+place+" three results for "+mtitle+":", color=0x53f442) finalcount = int(count)+2 while True: res = data[int(count)] resno = int(count)+1 res = omdb.get(imdbid=str(res), fullplot=False) embed.add_field(name= str(resno)+": "+res['title']+", "+str(res['year']), value=res['plot']) count+=1 if(count > finalcount): break return embed
def movieList(): i = 0 while i < 6: movie_list.append(top_6.results[i]['title']) i = i +1 #Takes titles from The Movie Database and uses the Open Movie database to get further info for m in movie_list: movie_info = omdb.get(title=m, fullplot=True, tomatoes=True) url_clean = movie_info["poster"] imdb_clean = movie_info["imdb_id"] imdb_id = re.sub(r'tt',"",imdb_clean) # trailers = requests.get('http://api.traileraddict.com/?imdb='+imdb_id+'&count=1&width=680') poster_image_url = re.sub(r'(^\[)\w|(\])+g',"",url_clean) movie_6.append(movies.Movie(m,[movie_info["plot"]],poster_image_url,imdb_id)) return movie_6
def request(item): try: movie = omdb.get(title=item[0], year=item[1], tomatoes=True, fullplot=True) except Exception as e: print e, "caused by", item[0] return None if str(movie) != "Item({})": mtitle = movie.title myear = movie.year plot = movie.plot mid = movie.imdb_id plot = plot.replace('\n', ' ') if True: return mid + " ||| " + mtitle + " ||| " + myear + " ||| " + plot else: return None
def search_by(title, year, fields, imdb_id=None): """Search movie infos using its title and year """ if (title, year) in CACHED_RESULTS: item = CACHED_RESULTS[(title, year)] logger.debug('Get from cache: %s' % item) else: query = {'fullplot': False, 'tomatoes': False} if imdb_id: query['imdbid'] = imdb_id else: query['title'] = title query['year'] = year logger.debug('Query: %s' % query) item = omdb.get(**query) if item: item['title'] = to_unicode(title) # force original title item = format_item(item) CACHED_RESULTS[(title, year)] = item elif not imdb_id and config['google_api_key']: imdb_id = google_search_by(title, year) if imdb_id: item = search_by(title, year, fields, imdb_id) return item
def search(): print 'hello' term = request.form['keyword'] session['keyword'] = term try: param = {"query": {"word":term,}} req = urllib2.Request("http://socialratingsearch-env.us-east-1.elasticbeanstalk.com/api/getContent") req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(param)).read() except: # take care of all those ugly errors if there are some print("error") data = json.loads(response) twitter = [] youtube = [] for line in data['results']: if line['type'] == "twitter": twitter.append(line['text']) elif line["type"] == "youtube": youtube.append(line['text']) youtube_comments = youtube twitter_comments = twitter print len(twitter_comments) print len(youtube_comments) twitter_score = 0 youtube_score = 0 global twitter_sample twitter_sample = [] if len(twitter_comments) > 0: k = spamclass(twitter_comments[:500],clf2,df10,wordcount2) twitter_pos = float(0) twitter_neutral = float(0) twitter_neg = float(0) count = 0 i = 0 for sen in k: data = urllib.urlencode({"text": sen.encode('utf-8')}) u = urllib.urlopen("http://text-processing.com/api/sentiment/", data) the_page = u.read() try: twitter_prob = ast.literal_eval(the_page)['probability'] twitter_pos += twitter_prob['pos'] #neutral += prob['neutral'] twitter_neg += twitter_prob['neg'] if i < 9: twitter_sample.append([sen,math.sqrt(twitter_prob['pos'])*10]) i += 1 except: count += 1 pass #twitter_sample = twitter_temp_sample print "twitter_pos: " + str(twitter_pos/(len(k)-count)) #print "neutral: " + str(neutral/len(k)) print "twitter_neg: " + str(twitter_neg/(len(k)-count)) twitter_score = math.sqrt(twitter_pos/(len(k)-count)) print term print "twitter_score: " + str(twitter_score*10) # df10 = df110.transpose() else: print "No tweets" #df10 = df110.transpose() global youtube_sample youtube_sample = [] if len(youtube_comments) > 0: k = spamclass(youtube_comments[:500],clf2,df10,wordcount2) youtube_pos = float(0) youtube_neutral = float(0) youtube_neg = float(0) count = 0 i = 0 for sen in k: data = urllib.urlencode({"text": sen.encode('utf-8')}) u = urllib.urlopen("http://text-processing.com/api/sentiment/", data) the_page = u.read() try: youtube_prob = ast.literal_eval(the_page)['probability'] youtube_pos += youtube_prob['pos'] youtube_neg += youtube_prob['neg'] if i < 9: youtube_sample.append([sen,math.sqrt(youtube_prob['pos'])*10]) i += 1 except: count += 1 pass #neutral += prob['neutral'] #youtube_sample = youtube_temp_sample print "youtube_pos: " + str(youtube_pos/(len(k)-count)) #print "neutral: " + str(neutral/len(k)) print "youtube_neg: " + str(youtube_neg/(len(k)-count)) youtube_score = math.sqrt(youtube_pos/(len(k)-count)) print term print "youtube_score: " + str(youtube_score*10) else: print "No youtubes" # print 'hello' # term = request.form['keyword'] # print term if len(twitter_sample) > 0: print twitter_sample if len(youtube_sample) > 0: print youtube_sample res = omdb.get(title=term, tomatoes=True) imdb_rating = res.imdb_rating print "imdb score: " + str(imdb_rating) term = res.title plot = res.plot tomato_rating = res.tomato_rating float_formatter = lambda x: "%.1f" % x youtube_rating = youtube_score*10 twitter_rating = twitter_score*10 if youtube_rating == 0: overall_rating = float_formatter(twitter_rating) youtube_img = "Images/NA.png" twitter_img = "Images/" + str(math.trunc(twitter_rating)) + ".png" elif twitter_rating == 0: overall_rating = float_formatter(youtube_rating) twitter_img = "Images/NA.png" youtube_img = "Images/" + str(math.trunc(youtube_rating)) + ".png" else: overall_rating = (youtube_rating + twitter_rating)/2 twitter_img = "Images/" + str(math.trunc(twitter_rating)) + ".png" youtube_img = "Images/" + str(math.trunc(youtube_rating)) + ".png" youtube_rating = float_formatter(youtube_rating) twitter_rating = float_formatter(twitter_rating) if (imdb_rating=="N/A"): imdb_rating = imdb_rating.replace("/", "") if (tomato_rating=="N/A"): tomato_rating = tomato_rating.replace("/", "") overall_rating = str(overall_rating) overall_img = "Images/" + overall_rating.split('.', 1)[0] + ".png" imdb_img = "Images/" + imdb_rating.split('.', 1)[0] + ".png" tomato_img = "Images/" + tomato_rating.split('.', 1)[0] + ".png" return render_template('ratings.html', keyword=term, plot=plot, imdb_rating=imdb_rating, youtube_rating=youtube_rating, \ tomato_rating=tomato_rating, twitter_rating=twitter_rating, overall_rating=overall_rating, overall_img=overall_img, \ youtube_img=youtube_img, twitter_img=twitter_img, imdb_img=imdb_img, tomato_img=tomato_img)
def get_movie(): reload(sys) # just to be sure sys.setdefaultencoding('utf-8') """ Strips out important sections of the IMDB rss feed and uses that data to pull more data from omdb and tmdb APIs """ csv_file = os.path.join(APP_STATIC, 'CSV/criterion.csv') file_object = codecs.open(csv_file, encoding='utf-8') csv_ratings = csv.reader(file_object) csv_ratings.next() for row in csv_ratings: tt_id = row[1] title = row[5] title = title.encode('utf-8') print title title_type = row[6] imdb_year = row[11] print imdb_year genre = row[12] director = row[7] imdb_rating = row[9] run_time = row[10] url = row[15] rating = 0 if imdb_rating == '': imdb_rating = 0 if run_time == '': run_time = 0 guide_url = guideIMDB + tt_id guide_request = requests.get(guide_url) guide_json = guide_request.json() if guide_json != {}: guide_id = guide_json.get('id') get_stream = 'x' print get_stream print guide_id else: guide_id = '' get_stream = '0' if not sess.query(Movie).filter(Movie.movie_id == tt_id).count(): if title_type != "TV Episode": if title_type != "": print 'hi' criterion = 0 omdb_search = omdb.get(imdbid=tt_id, fullplot=True) omdb_year = omdb_search.year omdb_year = int(omdb_year) plot = omdb_search.plot actors = omdb_search.actors country = omdb_search.country else: plot = 'NA' actors = 'NA' genre = 'NA' country = 'NA' try: a_query = tmdb.Movies(tt_id).info() time.sleep(0.01) poster_path = a_query['poster_path'] print type(poster_path) if isinstance(poster_path, unicode): poster = 'https://image.tmdb.org/t/p/w396' + poster_path print poster else: poster = STOCK_PHOTO print poster except requests.exceptions.RequestException: poster = STOCK_PHOTO mov = Movie(movie_id=tt_id, name=title, year=imdb_year, genre=genre, IMDBrating=imdb_rating, poster=poster, plot=plot, time=run_time, actors=actors, director=director, country=country, url=url, guideID=guide_id, getStream=get_stream, rating=rating, criterion=criterion) sess.add(mov) sess.commit() else: for movie in sess.query(Movie).filter(Movie.movie_id == tt_id).all(): movie.criterion = '0' movie.getStream = 'x' print movie.name + 'open' sess.commit()
def test_get(self): self.assertEqual(omdb.get(title='True Grit').title, 'True Grit') self.assertEqual(omdb.get(imdbid='tt0065126').imdb_id, 'tt0065126') self.assertEqual(omdb.get(search='True Grit')[0].title, 'True Grit')
def get_movie_watchlist(): """ Strips out important sections of the IMDB rss feed and uses that data to pull more data from omdb and tmdb APIs """ reload(sys) sys.setdefaultencoding('utf-8') xml_file = os.path.join(APP_STATIC, 'CSV/w_rss') # defines the rss feed untangle will parse rss_object = untangle.parse(xml_file) # creates python object from XML unicode_string # set variable to strip out IMDB username from <description> for item in rss_object.rss.channel.item: # looping over the python object of rss data title = (item.title.cdata) # create object of <title> children link = (item.link.cdata) # create object of <link> children to use for unique id's if not re.search('TV Episode', title): if not re.search('Documentary', title): # use regex to remove tv show and documentary ratings clean_title = stripped(title) # removes the date and parens from the <title> children tt_id = strip_id(link) # returns only the unique 'tt' imdb id clean_year = strip_year(title) if not sess.query(Movie).filter(Movie.movie_id == tt_id).count(): # removes imdb username from the <description> children print clean_title # returns only the rating from the already stripped <description> children watchlist = 'x' rating = 0 omdb_search = omdb.get(imdbid=tt_id, fullplot=True) omdb_year = omdb_search.year omdb_year = int(omdb_year) if omdb_year == clean_year: plot = omdb_search.plot actors = omdb_search.actors director = omdb_search.director year = int(omdb_year) genre = omdb_search.genre country = omdb_search.country if omdb_search.imdb_rating != 'N/A': imdb_rating = omdb_search.imdb_rating else: imdb_rating = 0.0 if omdb_search.runtime != 'N/A': rtime = omdb_search.runtime rtime = int(strip_numb(rtime)) else: rtime = None guide_url = guideIMDB + tt_id guide_request = requests.get(guide_url) guide_json = guide_request.json() if guide_json != {}: guide_id = guide_json.get('id') get_stream = 'x' print guide_id else: guide_id = '' get_stream = '0' else: plot = 'NA' actors = 'NA' director = 'NA' try: tmdb_query = tmdb.Movies(tt_id).info() time.sleep(0.01) poster_path = tmdb_query['poster_path'] print type(poster_path) if isinstance(poster_path, unicode): poster = 'https://image.tmdb.org/t/p/w396' + poster_path print poster else: poster = STOCK_PHOTO print poster except requests.exceptions.RequestException: poster = STOCK_PHOTO mov = Movie(movie_id=tt_id, name=clean_title, year=year, genre=genre, IMDBrating=imdb_rating, poster=poster, plot=plot, time=rtime, actors=actors, director=director, country=country, url=link, watchlist=watchlist, rating=rating, guideID=guide_id, getStream=get_stream) sess.add(mov) sess.commit()
def get_movie_ratings(): """ Strips out important sections of the IMDB rss feed and uses that data to pull more data from omdb and tmdb APIs """ reload(sys) sys.setdefaultencoding('utf-8') # required to decode unicode strings from imdb rss and tmdb API xml_file = os.path.join(APP_STATIC, 'CSV/rss') # defines the rss feed untangle will parse rss_object = untangle.parse(xml_file) # creates python object from xml_file unicode_string # set variable to strip out IMDB username from <description> for item in rss_object.rss.channel.item: # looping over the python object of rss data title = (item.title.cdata) # create object of <title> children desc = (item.description.cdata) # create object of <description> children (ratings info) link = (item.link.cdata) # create object of <link> children to use for unique id's if not re.search('TV Episode', title): if not re.search('Documentary', title): # use regex to remove tv show and documentary ratings clean_title = stripped(title) # removes the date and parens from the <title> children tt_id = strip_id(link) # returns only the unique 'tt' imdb id clean_year = strip_year(title) url = IMDB + tt_id if not sess.query(Movie).filter(Movie.movie_id == tt_id).count(): d_desc = strip_name(desc) # removes imdb username from the <description> children print title rating = strip_numb(d_desc) rating = int(rating) # returns only the rating from the already stripped <description> children omdb_search = omdb.get(imdbid=tt_id, fullplot=True) omdb_year = omdb_search.year omdb_year = int(omdb_year) get_stream = 'x' if omdb_year == clean_year: plot = omdb_search.plot actors = omdb_search.actors director = omdb_search.director year = int(clean_year) publish = 'unpublished' watchlist = '0' if omdb_search.imdb_rating != 'N/A': imdb_rating = omdb_search.imdb_rating else: imdb_rating = 0.0 if omdb_search.runtime != 'N/A': rtime = omdb_search.runtime rtime = int(strip_numb(rtime)) else: rtime = None guide_url = guideIMDB + tt_id guide_request = requests.get(guide_url) guide_json = guide_request.json() if guide_json != {}: guide_id = guide_json.get('id') print guide_id else: guide_id = '' get_stream = '0' else: plot = 'NA' actors = 'NA' director = 'NA' publish = 'unpublished' try: tmdb_query = tmdb.Movies(tt_id).info() time.sleep(0.01) poster_path = tmdb_query['poster_path'] print type(poster_path) if isinstance(poster_path, unicode): poster = 'https://image.tmdb.org/t/p/w396' + poster_path print poster else: poster = STOCK_PHOTO print poster except requests.exceptions.RequestException: poster = STOCK_PHOTO mov = Movie(movie_id=tt_id, name=clean_title, year=year,\ rating=rating, poster=poster, plot=plot,\ actors=actors, director=director, publish=publish,\ time=rtime, IMDBrating=imdb_rating, watchlist=watchlist,\ url=url, getStream=get_stream) sess.add(mov) try: sess.commit() print "Successfully Updated Ratings" except exc.SQLAlchemyError: sess.rollback() if sess.query(Movie).filter(Movie.movie_id == tt_id)\ .filter(Movie.watchlist == 'x').count(): for movie in sess.query(Movie).filter(Movie.movie_id == tt_id).all(): d_desc = strip_name(desc) rating = strip_numb(d_desc) rating = int(rating) movie.rating = rating movie.publish = 'unpublished' sess.commit() for watchlist_movie in sess.query(Movie).filter(Movie.rating > 1)\ .filter(Movie.watchlist == 'x').all(): print watchlist_movie.name watchlist_movie.watchlist = '0' sess.commit()
def _ep_data(show=None, season=None, episode=None): """Retrieves the info for an episode.""" metadata = omdb.get(title=show, season=season, episode=episode) return [(metadata[f] if f in metadata else None) for f in _EP_FIELDS]
def test_get_season_episode(self): self.assertEqual( omdb.get(title='Game of Thrones', season=1, episode=1).title, 'Winter Is Coming')
def com_omdb_get(self, media_title, media_year, media_fullplot, media_tomatoes): omdb.get(title=media_title, year=media_year, fullplot=media_fullplot, tomatoes=media_tomatoes)
def get_movie(): """ parses out downloaded IMDB watchlist CSV file, creates list object to import data to postgres. """ csv_file = os.path.join(APP_STATIC, 'CSV/watchlist.csv') file_object = codecs.open(csv_file, encoding='utf-8') csv_ratings = csv.reader(file_object) csv_ratings.next() for row in csv_ratings: tt_id = row[1] title = row[5] print title title_type = row[6] imdb_year = row[11] genre = row[12] director = row[7] imdb_rating = row[9] run_time = row[10] url = row[15] rating = 0 watchlist = 'x' if imdb_rating == '': imdb_rating = 0 if run_time == '': run_time = 0 if not sess.query(Movie).filter(Movie.movie_id == tt_id).count(): if title_type != "TV Episode": if title_type != "Documentary": omdb_search = omdb.get(imdbid=tt_id, fullplot=True) omdb_year = omdb_search.year omdb_year = int(omdb_year) print omdb_year plot = omdb_search.plot actors = omdb_search.actors country = omdb_search.country else: plot = 'NA' actors = 'NA' genre = 'NA' country = 'NA' try: tmdb_query = tmdb.Movies(tt_id).info() time.sleep(0.01) poster_path = tmdb_query['poster_path'] print type(poster_path) if isinstance(poster_path, unicode): poster = 'https://image.tmdb.org/t/p/w396' \ + poster_path print poster else: poster = STOCK_PHOTO print poster except requests.exceptions.RequestException: poster = STOCK_PHOTO mov = Movie(movie_id=tt_id, name=title, year=imdb_year, genre=genre, IMDBrating=imdb_rating, poster=poster, plot=plot, time=run_time, actors=actors, director=director, country=country, url=url, rating=rating, watchlist=watchlist) sess.add(mov) sess.commit() else: for movie in sess.query(Movie).filter(Movie.movie_id == tt_id).all(): movie.watchlist = 'x' print movie.name + 'open' sess.commit()