def save_movies(path_movies='csvData/movies.csv'): """Save all movies to movies table, add relations to all genres.""" with open(path_movies) as csvDataFile: """Save all movies to DB and add relations to genres.""" csvReader = csv.reader(csvDataFile) next(csvReader, None) # skip the headers for row in csvReader: movie = Movie(movie_id=row[0], title=row[1]) movie.save() genres = row[2].lower().replace("|", " ").split() add_genre_to_movie(movie, genres)
def index(request): for no in range(100, 1000): try: ID, TITLE, POSTER, PLOT, DL_LINK = lp.process(no) m = Movie(id=ID, title=TITLE, poster=POSTER, plot=PLOT, dl_link=DL_LINK) m.save() except: pass return HttpResponse("Done!") # Create your views here.
def add_movie(): movie_data = request.get_json() # print(request.get_data()) #apparently works with body, so you could use ifs to check for .content_type and act accordingly if movie_data == None: return "Empty request!", 400 movie = Movie(title=movie_data['title'], raiting=movie_data['raiting']) db.session.add(movie) db.session.commit() return "Done", 201 #you can also return a status code after a comma
def update_movie_table(): data = MoviesFilePreprocessor().run() if Movie.objects.all(): Movie.objects.all().delete() movie_objects = [ Movie(movie_id=key, title=data[key]['title'], year=data[key]['year'], genres=data[key]['genres']) for key in data.keys() ] Movie.objects.bulk_create(movie_objects)
def _movie_info(response_dict, movie_id_final, user=None): movie_image = MovieToPick._get_poster(movie_id_final) # import ipdb; ipdb.set_trace() # in case the json parser returned None if response_dict: movie_exists = Movie.objects.filter(imdb_id=response_dict['imdbID']).exists() if not movie_exists: movie = Movie() movie.imdb_id = response_dict['imdbID'] movie.title = response_dict['Title'] movie.year = response_dict['Year'] # movies not yet released do not have ratings try: movie.imdb_rating = float(response_dict['imdbRating']) except ValueError: pass movie.runtime = response_dict['Runtime'] movie.genre = response_dict['Genre'] movie.description = response_dict['Plot'] movie.starring = response_dict['Actors'] movie.written_by = response_dict['Writer'] movie.directed_by = response_dict['Director'] if movie_image is not None: movie.poster.save('%s.jpg' % movie.title, File(movie_image)) # this doesn't work yet to assign a creator to each movie: if user is not None: movie.created_by = user movie.save() return movie else: return Movie.objects.get(imdb_id=movie_id_final) else: return 'failed'
def update_douban(doubanlist): mlist = [] for it in doubanlist: m = Movie() try: #print "channel",it.channel if it.channel == 1: continue m.mid = int(it.id) m.url = it.url m.cname = it.cname m.ename = it.ename m.actors = it.actors m.director = it.director m.location = it.location m.type = it.type m.date = utils.get_date_from_string(it.date) if m.date == 0: continue m.rate = 0 if len(it.rate) > 0: m.rate = int(float(it.rate) * 10) m.votes = 0 if len(it.votes) > 0: m.votes = int(it.votes) if len(it.pic_url) > 5: m.pic_url = it.pic_url else: m.pic_url = "nopic" #print it.votes m.douban_link = "http://movie.douban.com/subject/" + it.id m.summary = it.summary m.imdb_link = it.imdb_link m.comment_link = it.comment_link #print "reviews",m.comment_link #print "summary",m.summary m.found_date = utils.get_date_now() m.runtime = it.runtime except Exception, e: traceback.print_exc(sys.stdout) print "ERROR:", e print "UPDATE ERROR: url=", it.url, it.raw continue mlist.append(m)
def update_douban(doubanlist): mlist = [] for it in doubanlist: m = Movie() try: print "channel",it.channel if it.channel ==1: continue m.mid = int(it.id) m.url = it.url m.cname = it.cname m.ename = it.ename m.actors = it.actors m.director = it.director m.location = it.location m.type = it.type m.date = get_date_from_string(it.date) if m.date ==0: continue m.rate=0 if len(it.rate)>0: m.rate=int(float(it.rate)*10) if m.rate ==0: continue m.votes=0 if len(it.votes)>0: m.votes=int(it.votes) if len(it.pic_url)>5: m.pic_url = it.pic_url else: m.pic_url ="nopic"; print it.votes m.douban_link ="http://movie.douban.com/subject/"+it.id m.summary = it.summary m.imdb_link = it.imdb_link m.comment_link = it.comment_link print "reviews",m.comment_link print "summary",m.summary time = datetime.datetime.now() m.found_date = int(time.strftime('%Y'))*10000+int(time.strftime('%m'))*100 +int(time.strftime('%d')) m.runtime = it.runtime except Exception,e: traceback.print_exc(sys.stdout) print "ERROR:",e print "UPDATE ERROR: url=",it.url,it.raw continue mlist.append(m)
def update_data(): mlist = [] for line in open(update_dir + '/movie'): flist = line.strip().split('\3') if len(flist) < 5: continue it = Movie() it.mid = int(flist[0]) it.cname = flist[1].strip() print it.cname it.ename = flist[2] it.actors = flist[3] it.director = flist[4] it.nation = flist[5] it.location = flist[6] it.type = flist[7] strdate = flist[8] it.date = 0 if '-' in strdate: try: numlist = strdate[0:10].split('-') it.date = int(numlist[0]) * 10000 + int( numlist[1]) * 100 + int(numlist[2]) except: it.date = 0 elif len(strdate) > 4: try: it.date = int(strdate[0:4]) * 10000 except: it.date = 0 it.rate = 0 if len(flist[10]) > 0: it.rate = int(float(flist[10]) * 10) print it.rate it.votes = 0 if len(flist[11]) > 0: it.votes = int(flist[11]) if len(flist[12]) > 0: it.pic_url = flist[12] print it.votes it.douban_link = "http://movie.douban.com/subject/" + flist[0] it.summary = flist[-1] it.imdb_link = flist[-3] it.comment_link = flist[-2] print "reviews", it.comment_link print "summary", it.summary it.runtime = flist[9] mlist.append(it) havein = Movie.objects.filter(mid__in=[it.mid for it in mlist]) midmap = {it.mid: 1 for it in havein} for m in mlist: if m.mid not in midmap: m.save()
def _movie_info(response_dict, movie_id_final, user=None): movie_image = MovieToPick._get_poster(movie_id_final) # import ipdb; ipdb.set_trace() # in case the json parser returned None if response_dict: movie_exists = Movie.objects.filter(imdb_id=response_dict["imdbID"]).exists() if not movie_exists: movie = Movie() movie.imdb_id = response_dict["imdbID"] movie.title = response_dict["Title"] movie.year = response_dict["Year"] # movies not yet released do not have ratings try: movie.imdb_rating = float(response_dict["imdbRating"]) except ValueError: pass movie.runtime = response_dict["Runtime"] movie.genre = response_dict["Genre"] movie.description = response_dict["Plot"] movie.starring = response_dict["Actors"] movie.written_by = response_dict["Writer"] movie.directed_by = response_dict["Director"] if movie_image is not None: movie.poster.save("%s.jpg" % movie.title, File(movie_image)) # this doesn't work yet to assign a creator to each movie: if user is not None: movie.created_by = user movie.save() return movie else: return Movie.objects.get(imdb_id=movie_id_final) else: return "failed"
def update_data(): mlist = [] for line in open(update_dir +'/movie'): flist = line.strip().split('\3') if len(flist) < 5: continue it = Movie() it.mid = int(flist[0]) it.cname = flist[1].strip() print it.cname it.ename = flist[2] it.actors = flist[3] it.director = flist[4] it.nation = flist[5] it.location = flist[6] it.type = flist[7] strdate = flist[8] it.date = 0 if '-' in strdate: try: numlist = strdate[0:10].split('-') it.date = int(numlist[0])*10000 +int(numlist[1])*100 +int(numlist[2]) except: it.date = 0 elif len(strdate)>4: try: it.date = int(strdate[0:4])*10000 except: it.date =0 it.rate=0 if len(flist[10])>0: it.rate=int(float(flist[10])*10) print it.rate it.votes=0 if len(flist[11])>0: it.votes=int(flist[11]) if len(flist[12])>0: it.pic_url = flist[12] print it.votes it.douban_link ="http://movie.douban.com/subject/"+flist[0] it.summary = flist[-1] it.imdb_link = flist[-3] it.comment_link = flist[-2] print "reviews",it.comment_link print "summary",it.summary it.runtime = flist[9] mlist.append(it) havein = Movie.objects.filter(mid__in=[it.mid for it in mlist ]) midmap = { it.mid:1 for it in havein } for m in mlist: if m.mid not in midmap: m.save()