def movieData(movieID): movieID = movieID.strip( '\n' ) # Newline character was preventing the movie table from being searchable by ID. data = { 'title': '', 'year': None, 'rating': None, 'plot': '', 'plot outline': '', 'genres': '', 'mpaa': 'Mpaa not available.', 'runtimes': '', 'full-size cover url': '', 'imdbId': movieID } movie = IMDb().get_movie(movieID) title = unicodedata.normalize('NFKD', movie['title']).encode('ascii', 'ignore') for key in data: if movie.has_key(key): if type(movie[key]) == type([]) and key != 'genres': movie[key] = movie[key][0] if type(movie[key]) == type(''): movie[key] = unicodedata.normalize('NFKD', movie[key]).encode( 'ascii', 'ignore') data[key] = movie[key] # print data[key] elif key != 'imdbId': print 'Error! {} not available in {}'.format(key, title) m = Movie( title=data['title'], year=data['year'], rating=data['rating'], plot=data['plot'], plotOutline=data['plot outline'], mpaa=data['mpaa'], runtimes=data['runtimes'], coverUrl=data['full-size cover url'], imdbId=data['imdbId'], ) m.save() gs = [Genre.objects.filter(name=g) for g in data['genres']] gs.append(Genre.objects.filter(name='New')) fg = [] for g in gs: if len(g) > 0: fg.append(g[0]) m.genres = fg m.save()
def movieData(movieID): movieID = movieID.strip('\n') # Newline character was preventing the movie table from being searchable by ID. data = {'title': '', 'year': None, 'rating': None, 'plot': '', 'plot outline': '', 'genres': '', 'mpaa': 'Mpaa not available.', 'runtimes': '', 'full-size cover url': '', 'imdbId': movieID} movie = IMDb().get_movie(movieID) title = unicodedata.normalize('NFKD', movie['title']).encode('ascii','ignore') for key in data: if movie.has_key(key): if type(movie[key]) == type([]) and key != 'genres': movie[key] = movie[key][0] if type(movie[key]) == type(''): movie[key] = unicodedata.normalize('NFKD', movie[key]).encode('ascii','ignore') data[key] = movie[key] # print data[key] elif key != 'imdbId': print 'Error! {} not available in {}'.format(key, title) m = Movie(title = data['title'], year = data['year'], rating = data['rating'], plot = data['plot'], plotOutline = data['plot outline'], mpaa = data['mpaa'], runtimes = data['runtimes'], coverUrl = data['full-size cover url'], imdbId = data['imdbId'], ) m.save() gs = [Genre.objects.filter(name = g) for g in data['genres']] gs.append(Genre.objects.filter(name = 'New')) fg = [] for g in gs: if len(g) > 0: fg.append(g[0]) m.genres = fg m.save()
def import_movie(movie_id): movie_id = movie_id.strip('\n') # Newline character was preventing the movie table from being searchable by ID. data = {'title': '', 'canonical title': '', 'year': None, 'rating': None, 'plot': '', # IMDB provides list of plots from different contributors. 'plot outline': '', 'genres': '', #IMDB provides list of genres. 'mpaa': 'Mpaa not available.', 'runtimes': '', 'full-size cover url': '', 'imdbId': movie_id, 'director': '', 'cast': '',} movie = IMDb().get_movie(movie_id) title = unicodedata.normalize('NFKD', movie['title']).encode('ascii','ignore') for key in data: if movie.has_key(key): if key == 'director' or key == 'cast': plist = [person['name'] for person in movie[key]] movie[key] = ', '.join(plist[0:3]) elif type(movie[key]) == type([]) and key != 'genres': movie[key] = movie[key][0] if type(movie[key]) == type(''): movie[key] = unicodedata.normalize('NFKD', movie[key]).encode('ascii','ignore') data[key] = movie[key] elif key != 'imdbId': print 'Error! {} not available in {}'.format(key, title) cover = None try: imagedata = urllib2.urlopen(data['full-size cover url']).read() cover = Photo(title=data['title'], title_slug = slugify(data['title'])) cover.image.save(data['imdbId'] + '.jpg', ContentFile(imagedata)) print "saved an image: " + data['title'] except Exception as e: print "Oh noes, an error" print e pass m = Movie(title = data['title'], canonicalTitle = data['canonical title'], year = data['year'], rating = data['rating'], plot = data['plot'], plotOutline = data['plot outline'], mpaa = data['mpaa'], runtimes = data['runtimes'], cover = cover, imdbId = data['imdbId'], director = data['director'], cast = data['cast'] ) m.save() try: gs = [Genre.objects.get(name = g) for g in data['genres']] except Exception as e: gs = [] print "No genre found for " + g gs.append(Genre.objects.get(name = 'New')) gs.append(Genre.objects.get(name = 'All')) m.genres = gs m.save()
def import_movie(movie_id): movie_id = movie_id.strip( '\n' ) # Newline character was preventing the movie table from being searchable by ID. data = { 'title': '', 'canonical title': '', 'year': None, 'rating': None, 'plot': '', # IMDB provides list of plots from different contributors. 'plot outline': '', 'genres': '', #IMDB provides list of genres. 'mpaa': 'Mpaa not available.', 'runtimes': '', 'full-size cover url': '', 'imdbId': movie_id, 'director': '', 'cast': '', } movie = IMDb().get_movie(movie_id) title = unicodedata.normalize('NFKD', movie['title']).encode('ascii', 'ignore') for key in data: if movie.has_key(key): if key == 'director' or key == 'cast': plist = [person['name'] for person in movie[key]] movie[key] = ', '.join(plist[0:3]) elif type(movie[key]) == type([]) and key != 'genres': movie[key] = movie[key][0] if type(movie[key]) == type(''): movie[key] = unicodedata.normalize('NFKD', movie[key]).encode( 'ascii', 'ignore') data[key] = movie[key] elif key != 'imdbId': print 'Error! {} not available in {}'.format(key, title) cover = None try: imagedata = urllib2.urlopen(data['full-size cover url']).read() cover = Photo(title=data['title'], title_slug=slugify(data['title'])) cover.image.save(data['imdbId'] + '.jpg', ContentFile(imagedata)) print "saved an image: " + data['title'] except Exception as e: print "Oh noes, an error" print e pass m = Movie(title=data['title'], canonicalTitle=data['canonical title'], year=data['year'], rating=data['rating'], plot=data['plot'], plotOutline=data['plot outline'], mpaa=data['mpaa'], runtimes=data['runtimes'], cover=cover, imdbId=data['imdbId'], director=data['director'], cast=data['cast']) m.save() try: gs = [Genre.objects.get(name=g) for g in data['genres']] except Exception as e: gs = [] print "No genre found for " + g gs.append(Genre.objects.get(name='New')) gs.append(Genre.objects.get(name='All')) m.genres = gs m.save()