Exemplo n.º 1
0
def load_csv(filename):

    movies = pd.read_csv(filename,
                         encoding='utf-8').sort_values(by=['movie_title'])
    for index, row in movies.iterrows():
        movie_title_parse = unicodedata.normalize(
            'NFKC', row['movie_title']).rstrip().replace(" ", "_")
        item_exists = Movie.query.filter(
            Movie.movie_title.contains(movie_title_parse)).first()

        if item_exists is None:
            movie = {
                'movie_title': movie_title_parse,
                'director_name': row['director_name'],
                'genres': row['genres'],
                'plot_keywords': row['plot_keywords'],
                'movie_imdb_link': row['movie_imdb_link'],
                'language': row['language'],
                'country': row['country'],
                'title_year': row['title_year'],
                'imdb_score': row['imdb_score'],
            }
            new_movie = Movie(**movie)
            db.session.add(new_movie)
        else:
            continue

    db.session.commit()
Exemplo n.º 2
0
 def post(self):
     try:
         user_id = get_jwt_identity()
         body = request.get_json()
         user = User.objects.get(id=user_id)
         movie = Movie(**body, added_by=user)
         movie.save()
         user.update(push__movies=movie)
         user.save()
         id = movie.id
         return {'id': str(id)}, 200
     except (FieldDoesNotExist, ValidationError):
         raise SchemaValidationError
     except NotUniqueError:
         raise MovieAlreadyExistsError
     except Exception as e:
         raise InternalServerError
Exemplo n.º 3
0
def create_movie():
    print(request)
    args = request.get_json()
    movie = Movie(title=args['title'],
                  format=args['format'],
                  length=args['length'],
                  release_year=args['release_year'],
                  rating=args['rating']).save()
    return movie
Exemplo n.º 4
0
def fetch_movie_data(movie_id):
    data = perform_request("movie_info", movie_id)

    if data:
        cast = data['credits']['cast']
        videos = data['videos']['results']

        movie = Movie(id=data['id'], imdb_id=data['imdb_id'], backdrop_path=data['backdrop_path'],
                      poster_path=data['poster_path'], adult=True if (data['adult'] == "true") else False,
                      title=data['title'], original_language=data['original_language'], overview=data['overview'],
                      release_date=_validate_date(data['release_date']), runtime=data['runtime'], status=data['status'],
                      tagline=data['tagline'], homepage=data['homepage'], revenue=data['revenue'],
                      budget=data['budget'])

        for g in data['genres']:
            genre = Genre.query.get(g['id'])
            if not genre:
                continue
            movie.genres.append(genre)

        for c in cast:
            actor = Actor.query.get(c['id'])
            if not actor:
                r = perform_request('person', c['id'])
                actor_null_check( r )
                actor = Actor(id=r['id'], biography=r['biography'], birthday=_validate_date(r['birthday']),
                              deathday=_validate_date(r['deathday']), homepage=r['homepage'],
                              name=r['name'], place_of_birth=r['place_of_birth'],
                              profile_path=r['profile_path'], imdb_id=r['imdb_id'])

            character = Character(character_name=c['character'], actor_name=c['name'], profile_path=c['profile_path'],
                                  cast_id=c['cast_id'], order=c['order'], credit_id=c['credit_id'], actor=actor)

            movie.characters.append(character)

        for v in videos:
            video = Video(iso_639_1=v['iso_639_1'], site=v['site'], key=v['key'], type=v['type'], name=v['name'])
            movie.videos.append(video)

        for c in data['production_countries']:
            country = Country.query.filter_by(iso_3166_1=c['iso_3166_1']).first()
            if country:
                movie.countries.append(country)
            else:
                movie.countries.append(Country(name=c['name'], iso_3166_1=c['iso_3166_1']))

        db.session.add(movie)
        db.session.commit()
Exemplo n.º 5
0
def list_movies():
    sort = request.args.get("sort")
    desc = request.args.get("desc")
    asc = request.args.get("asc")
    movies = Movie.scan()
    result = {}
    result['movies'] = [dict(movie) for movie in movies]
    if sort:
        if desc:
            result['movies'].sort(reverse=True, key=lambda i: (i[sort]))
        elif asc:
            result['movies'].sort(key=lambda i: (i[sort]))
        else:
            result['movies'].sort(key=lambda i: (i[sort]))
    result['count'] = movies._count
    return Response(json.dumps(result), mimetype='application/json')
Exemplo n.º 6
0
import json

from flask import Flask, request, Response
from api.models.movie import Movie

app = Flask(__name__)
if not Movie.exists():
    Movie.create_table(read_capacity_units=Movie.Meta.read_capacity_units,
                       write_capacity_units=Movie.Meta.write_capacity_units,
                       wait=True)


@app.route('/movies', methods=['GET'])
def list_movies():
    sort = request.args.get("sort")
    desc = request.args.get("desc")
    asc = request.args.get("asc")
    movies = Movie.scan()
    result = {}
    result['movies'] = [dict(movie) for movie in movies]
    if sort:
        if desc:
            result['movies'].sort(reverse=True, key=lambda i: (i[sort]))
        elif asc:
            result['movies'].sort(key=lambda i: (i[sort]))
        else:
            result['movies'].sort(key=lambda i: (i[sort]))
    result['count'] = movies._count
    return Response(json.dumps(result), mimetype='application/json')

Exemplo n.º 7
0
 def get(self):
     query = Movie.objects()
     movies = Movie.objects().to_json()
     return Response(movies, mimetype="application/json", status=200)