def quick_edit_movie(movie_id): edited_movie = sess.query(Movie).filter_by(movie_id=movie_id).one() if 'email' in login_session: if login_session['email'] == '*****@*****.**': if request.method == 'POST': if request.form['rating']: edited_movie.rating = request.form['rating'] if request.form['publish']: edited_movie.publish = request.form['publish'] sess.add(edited_movie) try: sess.commit() except exc.SQLAlchemyError: flash("SQlalchemy error, session rollback initiated") sess.rollback() return redirect(url_for('show_admin_movie_list')) else: return render_template('edit_rating.html', movie=edited_movie) else: flash("You are Not Authorized to View the Admin Page") return redirect('/movie/') else: flash("You are Not Authorized to View the Admin Page") return redirect('/movie/')
def edit_movie(movie_id): if 'email' in login_session: if login_session['email'] == '*****@*****.**': edited_movie = sess.query(Movie).filter_by(movie_id=movie_id).one() if request.method == 'POST': if request.form['name']: edited_movie.name = request.form['name'] if request.form['poster']: edited_movie.poster = request.form['poster'] if request.form['year']: edited_movie.year = request.form['year'] if request.form['rating']: edited_movie.rating = request.form['rating'] if request.form['actors']: edited_movie.actors = request.form['actors'] if request.form['director']: edited_movie.director = request.form['director'] if request.form['plot']: edited_movie.plot = request.form['plot'] if request.form['mtype']: edited_movie.mtype = request.form['mtype'] if request.form['publish']: edited_movie.publish = request.form['publish'] if request.form['stream']: edited_movie.getStream = request.form['stream'] sess.add(edited_movie) if request.form['guideid']: edited_movie.guideID = request.form['guideid'] if request.form['criterion']: edited_movie.criterion = request.form['criterion'] try: sess.commit() except exc.SQLAlchemyError: flash("SQlalchemy error, session rollback initiated") sess.rollback() return redirect(url_for('show_admin_movies')) else: return render_template('edit_movie.html', movie=edited_movie) else: flash("You are Not Authorized to View the Admin Page") return redirect('https://www.google.com') else: flash("You are Not Authorized to View the Admin Page") return redirect('/movie/')
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()