def get_movie(movie_id): """Return movie from themoviedb API by given movie id.""" # Create movie object which contain information about movie movie = Movie(movie_id) movie.load(config) # Get user's rating for movie user_movierating = None if "logged_in_user_id" in session: user_id = session["logged_in_user_id"] user_movierating = mu.get_user_movie_rating(movie_id, user_id) return render_template("movie_details.html", movie=movie, user_movierating=user_movierating)
def SearchMovie(): conn = pymssql.connect(server=ip, user=id, password=pw, database=db) cursor = conn.cursor() query = 'SELECT * FROM MOVIE_LIST' cursor.execute(query) movie_list = list() row = cursor.fetchone() while row: _code = row[0] _title = row[1] _story = row[2] _genre = row[3] _rating = row[4] _run_time = row[5] _open_date = row[6] m = Movie(_code, _title, _story, _genre, _rating, _run_time, _open_date) movie_list.append(m) row = cursor.fetchone() return movie_list
def SearchMovie(): conn = NewConnect() cursor = conn.cursor() query = 'SELECT * FROM MOVIE_LIST' cursor.execute(query) movie_list = list() row = cursor.fetchone() while row: _code = row[0] _title = row[1] _story = row[2] _genre = row[3] _rating = row[4] _run_time = row[5] _open_date = row[6] _casting_count = row[7] m = Movie(_code, _title, _story, _genre, _rating, _run_time, _open_date, _casting_count) movie_list.append(m) print(m.code, m.title, m.story, m.genre, m.rating, m.run_time, m.open_date, m.casting_count) row = cursor.fetchone() return movie_list
def get_random_movie(logged_in_user_id, current_movie_id): """Return random movie from themoviedb API.""" if current_movie_id is None: # Get random movie id from themoviedb API current_movie_id = rh.get_random_movie_id(config, logged_in_user_id) # Create movie object which contain information about movie" movie = Movie(current_movie_id) movie.load(config) # worker to store movie using Redis # put inf about random movie in db movie_json = json.dumps(movie, cls=ComplexEncoder) result = mu.Result(result=movie_json) mu.db.session.add(result) mu.db.session.commit() return result.id
def get_random_movie(): """Return random movie from themoviedb API.""" if "random_movie_id" not in session: # Get random movie id from themoviedb API movie_id = rh.get_random_movie_id(config) else: movie_id = session["random_movie_id"] # Create movie object which contain information about movie" movie = Movie(movie_id) movie.load(config) # if user login add movie to user's movie list if "logged_in_user_id" in session: mu.add_movie(movie, session["logged_in_user_id"]) session["random_movie_id"] = movie_id return render_template("movie_details.html", movie=movie)
def get_cast_graph(): """Collect information for drawing cast graph Return json: {"nodes": [{"name": actor's name, "url": url actor's photo, "wiki": wikipedia link}, ], "links": [{"source": actor1's index in "nodes", "target": actor2's index in "nodes", "movies": intersection of movies }, ] } """ movie_id = request.args.get("movie_id") # Create Movie object which contains only movie, actors and directors movie = Movie(movie_id) movie.load_crew(config) # Create cast graph (5 actors and director) cast_graph = rh.create_cast_graph_json(config, movie) return jsonify(cast_graph)
def get_movie(movie_id): """Return movie from themoviedb API by given movie id.""" # Create movie object which contain information about movie movie = Movie(movie_id) movie.load(config) # Classify each movie review as positive or negative classify_reviews(movie) print "*****************************SERVER GET_MOVIE Print reviews:" for review in movie.reviews: print review # Get user's rating for movie user_movierating = None if "logged_in_user_id" in session: user_id = session["logged_in_user_id"] user_movierating = mu.get_user_movie_rating(movie_id, user_id) return render_template("movie_details.html", movie=movie, user_movierating=user_movierating)
def show_random_movie(job_id): """Display random movie which stored by Redis""" job = Job.fetch(job_id, connection=conn) if job.is_finished: result = mu.Result.query.filter_by(id=job.result).first() movie_json = json.loads(result.result) movie = Movie.load_from_JSON(movie_json, config) if movie is not None: # Classify each movie review as positive or negative classify_reviews(movie) # if user login add movie to user's movie list session[ "random_movie_id"] = movie.id # movie id from themoviedb API if "logged_in_user_id" in session: mu.add_movie(movie, session["logged_in_user_id"]) return render_template("movie_details.html", movie=movie) return redirect('/')
#tds = table.find_elements_by_xpath('//td') for tr in trs: tds = tr.find_elements_by_xpath('.//td') if len(tds) == 0 or len(tds) == 1: continue img = tds[0].find_element_by_xpath('.//img') alt = img.get_attribute('alt') rank = int(alt) title = tds[1].text #print(title) movie = Movie(title, rank) movies.append(movie) driver.quit() f = open('c:/07.27-12.1_CLOUD/python/movielist.txt', 'w', encoding='utf8') for m in movies: f.write('{0}위: {1}\n'.format(m.rank, m.title)) for m in movies: print(m.rank, m.title) #//*[@id="old_content"]/table #xpath는 html에서의 위치 #xpath를 통해 셀레니움이 드라이버에서 알아서 찾아서 찾아감
ename = li.find_element_by_xpath('.//*[@class="e_name"]').text p_part = li.find_element_by_xpath('.//*[@class="p_part"]').text pe_cmt = '' try: pe_cmt = li.find_element_by_xpath('.//*[@class="pe_cmt"]').text except: pe_cmt = '없음' #print(actname, ename, p_part, pe_cmt) act = Actor(actname, ename, p_part, pe_cmt) act_list.append(act) #print('제목: {0}\t제작국가: {1}'.format(title.text, nation.text)) #for act in act_list: # print('{0}: {1} ({2})'.format(act.p_part, act.actname, act.ename)) # 된사람들은 타이틀 , 네이션을 포함한 act_list를 (어벤져스의 한 세트이므로) 이것들을 한번에 아우를 수 있는 movie class를 만들어보세요 mov = Movie(title.text, nation.text, act_list) movies.append(mov) print('완료: {0}, 배우: {1}명'.format(mov.title, len(mov.acts))) print('{0} 페이지 완료'.format(count)) #print(mov.title, mov.nation, mov.acts[i].actname, mov.acts[i].ename, mov.acts[i].p_part, mov.acts[i].pe_cmt) # for act in mov.acts: # print(act.actname, act.ename, act.p_part, act.pe_cmt)
from model_movie import Movie movie_list = list() command = '' cnt = 0 while command.upper() != "EXIT": command = input('명령을 입력해주세요:\t') if command == '1': m = Movie(input('영화 제목을 입력해주세요!:\t')) cnt += 1 movie_list.append(m) m.show(cnt)