def new_movie_form(): movie_name = request.form['movie_name'] print(f"Movie Name: {movie_name}") movie = Movie() print(f"Movie ID: {movie.movieid}") movie.title = movie_name data.create_movie(movie) return redirect(url_for('list_all_movies'))
def check_movie(): movie_name = request.form['movie_name'] if data.check_movies_exist(movie_name) == True: print("check this") flash('Movie already exists in database') return redirect(url_for('movie_form')) else: print("check that") movie_name = request.form['movie_name'] print(f"Movie Name: {movie_name}") movie = Movie() print(f"Movie ID: {movie.movieid}") movie.title = movie_name data.create_movie(movie) return redirect(url_for('list_all_movies'))
def test_equal(self): the_godfather = Movie('The Godfather', 1972) movie = Movie('Inception', 2010) self.assertNotEqual(the_godfather, movie) movie.title, movie.year = 'The Godfather', 1972 self.assertEqual(the_godfather, movie)
movie = Movie() # 主演 movie.actors = tag.attrs['data-actors'] # 导演 movie.director = tag.attrs['data-director'] # 时长 movie.duration = tag.attrs['data-duration'] # 豆瓣评分 movie.rate = tag.attrs["data-rate"] # 发布地区 movie.region = tag.attrs["data-region"] # 发布时间 movie.release = tag.attrs["data-release"] # 电影名称 movie.title = tag.attrs["data-title"] # 相关视频地址 movie.trailer = tag.attrs["data-trailer"] # 电影封面 movie.cover = tag.img.attrs["src"] # 豆瓣地址 movie.threadUrl = tag.a.attrs["href"] print(movie) movies.append(movie) # ls = tag.li # for li in ls: # print("--------")
def get_info(): global stage time.sleep(5) print "-CRAWLER- Start to get movie feature..." while (not mvIDQ.empty()) or stage == 0: try: mvID = mvIDQ.get() # get info from imdmpy with movie id # print "-CRAWLER- Getting movie(id: %s) feature..." % mvID mvIN = imdb_access.get_movie(mvID) # create new Movie object mvOJ = Movie() # ID string mvOJ.id = mvID # title string mvOJ.title = mvIN.get('title') # poster url string mvOJ.cover_url = mvIN.get('cover url') # Bigger poster url string mvOJ.giant_cover_url = mvIN.get('full-size cover url') # genres string list if mvIN.has_key('genres'): sIN = "" for i in mvIN.get('genres'): sIN += (i + '$') mvOJ.genres = sIN[0:len(sIN) - 1] # color string list if mvIN.has_key('color info'): sIN = "" for i in mvIN.get('color info'): sIN += (i + '$') mvOJ.color_info = sIN[0:len(sIN) - 1] # director string list if mvIN.has_key('director'): sIN = "" for i in mvIN.get('director'): sIN += i['name'] + '$' mvOJ.director = sIN[0:len(sIN) - 1] # 1st Actor mvOJ.cast_1st = mvIN.get('cast')[0]['name'] if len(mvIN.get('cast')) >= 2: # 2nd Actor mvOJ.cast_2nd = mvIN.get('cast')[1]['name'] if len(mvIN.get('cast')) >= 3: # 3rd Actor mvOJ.cast_3rd = mvIN.get('cast')[2]['name'] # country string list if mvIN.has_key('countries'): sIN = "" for i in mvIN.get('countries'): sIN += (i + '$') mvOJ.countries = sIN[0:len(sIN) - 1] # language string list if mvIN.has_key('languages'): sIN = "" for i in mvIN.get('languages'): sIN += (i + '$') mvOJ.languages = sIN[0:len(sIN) - 1] # writer string list if mvIN.has_key('writer'): sIN = "" for i in mvIN.get('writer'): sIN += i['name'] + '$' mvOJ.writer = sIN[0:len(sIN) - 1] # editor string list if mvIN.has_key('editor'): sIN = "" for i in mvIN.get('editor'): sIN += i['name'] + '$' mvOJ.editor = sIN[0:len(sIN) - 1] # cinematographer string list if mvIN.has_key('cinematographer'): sIN = "" for i in mvIN.get('cinematographer'): sIN += i['name'] + '$' mvOJ.cinematographer = sIN[0:len(sIN) - 1] # art direction string list if mvIN.has_key('art direction'): sIN = "" for i in mvIN.get('art direction'): sIN += i['name'] + '$' mvOJ.art_director = sIN[0:len(sIN) - 1] # costume designer string list if mvIN.has_key('costume designer'): sIN = "" for i in mvIN.get('costume designer'): sIN += i['name'] + '$' mvOJ.costume_designer = sIN[0:len(sIN) - 1] # music By string list if mvIN.has_key('original music'): sIN = "" for i in mvIN.get('original music'): sIN += i['name'] + '$' mvOJ.original_music = sIN[0:len(sIN) - 1] # sound string list if mvIN.has_key('sound mix'): sIN = "" for i in mvIN.get('sound mix'): sIN += (i + '$') mvOJ.sound_mix = sIN[0:len(sIN) - 1] # production company string list if mvIN.has_key('production companies'): sIN = "" for i in mvIN.get('production companies'): sIN += i['name'] + '$' mvOJ.production_companies = sIN[0:len(sIN) - 1] # year int if mvIN.has_key('year'): mvOJ.year = mvIN.get('year') else: mvOJ.year = 0 # running time int if mvIN.has_key('runtimes'): try: if str(mvIN.get('runtimes')[0]).find(':') != -1: mvOJ.runtimes = int( str(mvIN.get('runtimes')[0]).split(':')[1]) else: mvOJ.runtimes = int(mvIN.get('runtimes')[0]) except Exception: mvOJ.runtimes = 0 else: mvOJ.runtimes = 0 # budget int # if 'budget' in mvIN: # mvOJ.budget = mvIN.get('budget') # get rating for old movies if mode == "old": mvOJ.number_of_votes = get_rating(mvID) mvINQ.put(mvOJ) mvIDQ.task_done() # print '-CRAWLER- Get movie features(ID: %s) successfully.' % mvID # TODO cannot handle exception except Exception, e: print '-CRAWLER- An {} exception occured!'.format(e), mvID mvINQ.put(mvID) time.sleep(1)