本文整理汇总了Python中models.Movie类的典型用法代码示例。如果您正苦于以下问题:Python Movie类的具体用法?Python Movie怎么用?Python Movie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Movie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self, name):
if not users.get_current_user():
self.redirect(users.create_login_url(self.request.uri))
results = search_metacritic(name, 'movie')
output = []
for result in results:
query = Img.all()
query.filter('url =', result[1])
img = query.fetch(1)[0]
query = Movie.all()
query.filter('cover =', img)
if not query.count():
movie = Movie(name=str(result[0]),cover=img,score=str(result[2]))
movie.put()
else:
movie = query.fetch(1)[0]
output.append([img.key().id(), result[0], movie.key().id()])
template_values = {'results': output}
path = os.path.join(os.path.dirname(__file__), 'search.html')
self.response.out.write(template.render(path, template_values))
示例2: users_get
def users_get(self, request):
"""Exposes an API endpoint to obtain the details of the User
Args:
request: Void message request, because the info comes from the JWT
Returns:
An Instance containing the User Details.
"""
#get jwt and validates if user exists
selected_user = self.validate_jwtoken(self.request_state)
list_of_voted_movies_query = MovieRankingUser.query(MovieRankingUser.user==selected_user.key).fetch()
list_of_voted_movies = []
list_of_voted_movie_keys_to_exclude = []
for user_movie_relation in list_of_voted_movies_query:
current_movie = Movie.query(Movie.key==user_movie_relation.movie).get()
list_of_voted_movies.append(current_movie.to_message())
#puts the voted movie keys in a list to exclude
list_of_voted_movie_keys_to_exclude.append(current_movie.key)
#all movies in the system
total_list_of_movies = Movie.query().order(Movie.title)
#removes the voted movies from the total
list_of_not_voted_movies_query = [res for res in total_list_of_movies.fetch() if res.key not in list_of_voted_movie_keys_to_exclude]
#transforms the movies to messages
list_of_not_voted_movies = [system_movie.to_message() for system_movie in list_of_not_voted_movies_query]
return selected_user.to_message(votes_movies=list_of_voted_movies, not_votes_movies=list_of_not_voted_movies)
示例3: movies_vote
def movies_vote(self, request):
"""Exposes an API endpoint to insert the new votes from the user
Args:
request: A list of the movies the user currently likes and cast a vote.
Returns:
A void message if everthing goes well or an error.
"""
#get jwt and validates if user exists
selected_user = self.validate_jwtoken(self.request_state)
list_of_voted_movies_query = MovieRankingUser.query(MovieRankingUser.user==selected_user.key).fetch()
for user_movie_relation in list_of_voted_movies_query:
current_movie = Movie.query(Movie.key==user_movie_relation.movie).get()
current_counter = current_movie.number_of_users_who_voted
current_movie.number_of_users_who_voted = current_counter - 1
current_movie.put()
user_movie_relation.key.delete()
for voted_movie in request.voted_movies:
current_movie = Movie.get_by_id(voted_movie.movie_identifier)
current_counter = current_movie.number_of_users_who_voted
current_movie.number_of_users_who_voted = current_counter + 1
new_movie_user_vote = MovieRankingUser(user=selected_user.key,movie=current_movie.key)
current_movie.put()
new_movie_user_vote.put()
return VoteResponse(status_msg='Vote casted with success.')
示例4: start_tr
def start_tr(self, attrs):
if self.break_tag == True:
return
if self.start_tag == True and self.tbody_tag == True:
movie = Movie()
movie.movie_status = 'new'
movie.movie_magnet_count = 0
self.movies.append(movie)
示例5: create
def create(self):
if request.method == 'POST':
if request.form.get('message'):
Movie.create(
title=request.form['title'],
release=request.form['release'],
description=request.form['description'],
poster=request.form['poster']
)
next = request.form.get('next') or self.dashboard_url()
return redirect(next)
示例6: getDetails
def getDetails(identifiers):
try:
movie=Movie.objects.get(sourceID=identifiers.sourceID,source=identifiers.source)
except:
movie=Movie()
if identifiers.source=='rottenTomatoes':
movie=fetchDetailsRottenTomatoes(identifiers)
elif identifiers.source=='theMovieDB':
movie=fetchDetailsTheMovieDB(identifiers)
movie.save()
return movie
示例7: saveMovie
def saveMovie (request):
channel=Channel.objects.get(id=1)
html = urllib.urlopen('http://sh.meituan.com/dianying').read()
soup = BeautifulSoup(html)
for movie in soup.find_all('ul', class_='reco-slides__slides')[0].find_all('li')[0].find_all('a',class_='btn'):
name = movie['title']
href = movie['href']
code = href[href.rfind('/') + 1:href.find('#')]
m = Movie(name=name,code=code,channel=channel)
m.save()
return HttpResponse("save success! ")
示例8: post
def post(self):
title = self.request.get("title")
url = self.request.get("url")
rate = self.request.get("rate")
movie = Movie(title=title,url=url,rate=rate)
movie.put()
params = {"title":title,"url":url,"movie":movie,"rate":rate}
self.render_template("film_izpis.html",params=params)
示例9: add_movie
def add_movie():
title = request.form.get('title')
imdb_id = request.form.get('imdb_id')
if title is not None and imdb_id is not None:
url = "http://www.imdb.com/title/" + imdb_id
img_src = get_img_url(url)
movie = Movie(title=title, imdb_id=imdb_id, url=url, img_src=img_src, votes=0)
Session().add(movie)
Session().commit()
return flask.jsonify(movie.as_dict()), 201
else:
return "Invalid request", 400
示例10: retrieve_movie_from_id
def retrieve_movie_from_id(movie_id):
"""
Retrieve movie info from IMDB by movie id.
:param movie_id: original title of the film to retrieve info
:type movie_id: string
:return: Movie's key
:rtype: ndb.Key
:raise RetrieverError: if there is an error from MYAPIFILMS
"""
logging.info('Retrieving %s', movie_id)
url = BASE_URL_MYAPIFILMS + 'imdb?idIMDB=' + movie_id + '&format=JSON&aka=1&business=0&seasons=0&seasonYear=0&technical=0&filter=N&exactFilter=0&limit=1&lang=en-us&actors=S&biography=0&trailer=1&uniqueName=0&filmography=0&bornDied=0&starSign=0&actorActress=0&actorTrivia=0&movieTrivia=0&awards=0&token=307cccfe-d20b-4b69-b976-d6a024538864'
json_page = get(url).encode('utf-8')
json_data = json.loads(json_page)
movie = Movie(id=json_data['idIMDB'],
plot=json_data['plot'],
poster=clear_url(json_data['urlPoster']) if ('urlPoster' in json_data and json_data['urlPoster'] != "") else None,
rated=json_data['rated'],
simple_plot=json_data['simplePlot'],
genres=json_data['genres'])
try:
trailer_url = json_data['trailer']['videoURL']
movie.trailer = trailer_url
except KeyError:
movie.trailer = None
movie.original_title = json_data['title']
akas = json_data['akas']
for aka in akas:
if aka['country'] == 'Italy':
movie.title = aka['title']
run_times = json_data['runtime']
if len(run_times) == 0:
movie.run_times = None
else:
movie.run_times = run_times[0]
year = json_data['year']
if len(year) > 4:
year = year[-4:]
movie.year = year
key = movie.put()
actors_list = json_data['actors']
directors_list = json_data['directors']
writers_list = json_data['writers']
retrieve_artists(movie, actors_list, directors_list, writers_list)
logging.info('Retrieved %s', movie_id)
return key
示例11: get_movie
def get_movie(request, pk):
"""
function to handle request for a particular movie
GET => uesd to query
POST w/o id, to insert and return inserted value
POST w/ id, to update existing record
:param request: incomming http request
:param pk: primary key of the movie requested
:return:
"""
#check the incomming method
try:
if request.method == "GET":
if pk != '':
_movie = Movie.objects.get(pk=pk).json()
response = HttpResponse(_movie, content_type="application/json")
return response
else:
response = search_movie(request)
return response
raise Movie.MultipleObjectsReturned()
elif request.method == 'POST':
#check if user is authenticated to touch it
#if pk='', insert, else overwrite
if pk == '' and has_perm(request, 'IMDB.create_movie'):
_m = Movie()
elif pk != '' and has_perm(request, 'IMDB.change_movie'):
_m = get_object_or_404(Movie, pk=pk)
else:
raise PermissionDenied()
_m.add_using_json(request.body)
_m.save()
return HttpResponse(_m.json(), content_type="application/json", status=201)
elif request.method == 'DELETE':
if pk != '':
if has_perm(request, 'delete_movie'):
_m = get_object_or_404(Movie, pk=pk)
_m.delete()
return HttpResponse('delete successful', content_type="application/json", status=200)
else:
raise PermissionDenied()
else:
raise Movie.MultipleObjectsReturned()
else:
raise Movie.MultipleObjectsReturned() #avoiding modification to the entire series
except IntegrityError as ie:
return HttpResponseBadRequest("{'status':400,'message':'Bad Request -- Integrity violation:" + ie.message + "'}",
content_type="application/json")
except KeyError as k:
return HttpResponseBadRequest("{'status':400,'message':'Bad Request -- Key violation:" + k.message + "'}",
content_type="application/json")
except Movie.MultipleObjectsReturned as e:
return HttpResponseNotFound(json.dumps({'status': 404, 'message': 'movie not found'}),
content_type="application/json")
except (Movie.DoesNotExist, Http404):
return HttpResponseNotFound(json.dumps({'status': 404, 'message': 'movie not found'}),
content_type="application/json")
except PermissionDenied as p:
return HttpResponseForbidden(json.dumps({'status': 403, 'message': 'Permission Denied{0:s}'.format(p.message)}),
content_type="application/json")
示例12: add_movie
def add_movie():
input_title = flask.request.values['title']
if not input_title:
flask.flash('Blank movie title.', 'danger')
else:
imdb = imdbpie.Imdb()
# first we check if input_title is an id or URL:
movie_id = imdb.validate_id(input_title)
if not movie_id:
title = imdb.find_by_title(input_title)
if title:
movie_id = title[0]['imdb_id']
if movie_id:
movie_info = imdb.find_movie_by_id(movie_id)
new_movie = Movie.create_scheduled(
title=movie_info.title,
year=movie_info.year,
imdb_id=movie_info.imdb_id,
imdb_rating=movie_info.rating,
imdb_cover_url=movie_info.data['image']['url']
)
flask.flash('Movie "{}" was added.'.format(new_movie['title']), 'success')
return flask.redirect(flask.url_for('admin'))
示例13: add_movie_tastes
def add_movie_tastes(user_id, movie_id, taste):
taste = float(taste)
user = User.get_by_id(user_id)
movie = Movie.get_by_id(movie_id)
for actor in movie.actors:
artist = Artist.get_by_id(actor.id())
user.add_taste_artist(artist, ACTOR_WEIGHT * taste)
for director in movie.directors:
artist = Artist.get_by_id(director.id())
user.add_taste_artist(artist, DIRECTOR_WEIGHT * taste)
for writer in movie.writers:
artist = Artist.get_by_id(writer.id())
user.add_taste_artist(artist, WRITER_WEIGHT * taste)
for genre in movie.genres:
user.add_taste_genre(genre, GENRE_WEIGHT * taste)
user.remove_proposal()
user.put()
taskqueue.add(url='/api/proposal/' + user.key.id(), method='GET')
return 'OK'
示例14: save
def save(guess, user_id, movie_id):
user = User.from_id(user_id)
rating = Movie.from_id(movie_id).rating
guess_id = None
connection = connect()
try:
with connection.cursor() as cursor:
sql = """INSERT INTO `guesses` (guess, user_id, movie_id, diff)
VALUES (%s, %s, %s, %s)"""
cursor.execute(
sql,
(
guess,
user_id,
movie_id,
Guess.calculate_score(rating, guess)
)
)
guess_id = cursor.lastrowid
sql = """SELECT SUM(`diff`) AS score
FROM `guesses` WHERE `user_id`=%s"""
cursor.execute(sql, (user_id))
result = cursor.fetchone()
user.score = result[u'score']
connection.commit()
finally:
connection.close()
user.update()
return Guess.from_id(guess_id)
示例15: post_comment
def post_comment():
title = request.form['title']
contents = request.form['contents']
if contents:
m = Movie.get_or_create(title)
m.add_comment(Comment(user_id=g.user.id, contents=contents))
return redirect(url_for("show_movie", title=title))