<commit_before>from __future__ import unicode_literals, division, absolute_import

import copy
import logging

from flask import jsonify, request

from flexget.api import api, APIResource
from flexget.plugins.api.movie_queue import empty_response
from flexget.plugins.list.movie_list import PluginMovieList as ml

log = logging.getLogger('movie_list')

movie_list_api = api.namespace('movie_list', description='Movie List operations')

base_movie_entry = {
    'type': 'object',
    'properties': {
        'title': {'type': 'string'},
        'url': {'type': 'string'},
        'movie_name': {'type': 'string'},
        'movie_year': {'type': 'integer'}
    },
    'additionalProperties': True,
    'required': ['url'],
    'anyOf': [
        {'required': ['title']},
        {'required': ['movie_name', 'movie_year']}
    ]

}

return_movie_entry = copy.deepcopy(base_movie_entry)
return_movie_entry['properties']['id'] = {'type': 'integer'}
return_movie_entry['properties']['list_name'] = {'type': 'string'}

return_movie_list = {
    'type': 'object',
    'properties': {
        'movies': {
            'type': 'array',
            'items': return_movie_entry
        },
        'number_of_movies': {'type': 'integer'},
        'list_name': {'type': 'string'}
    }
}

base_movie_entry_schema = api.schema('base_movie_entry', base_movie_entry)
return_movie_entry_schema = api.schema('return_movie_entry_schema', return_movie_entry)
movie_list_return_schema = api.schema('movie_list_return_model', return_movie_list)


@movie_list_api.route('/<string:list_name>')
@api.doc(params={'list_name': 'Name of the list'})
class MovieListAPI(APIResource):
    @api.response(code_or_apierror=200, model=movie_list_return_schema)
    def get(self, list_name, session=None):
        ''' Get Movie list entries '''
        # TODO Pagination
        movies = [dict(movie) for movie in ml.get_list(list_name)]
        return jsonify({'movies': movies,
                        'number_of_entries': len(movies),
                        'list_name': list_name})

    @api.validate(base_movie_entry_schema)
    @api.response(201, model=return_movie_entry_schema)
    @api.doc(description="This will create a new list if list name doesn't exist")
    def post(self, list_name, session=None):
        ''' Adds a movie to the list. '''
        data = request.json
        movies = ml.get_list(list_name)

        movie = movies.add(data, session=session)
        return movie, 201

    @api.validate(base_movie_entry_schema)
    @api.response(200, model=empty_response)
    def delete(self, list_name, session=None):
        ''' Remove an movie from the list '''
        data = request.json
        entries = ml.get_list(list_name)
        entries.discard(data)
        return {}<commit_msg>Added get/delete for specific movie id<commit_after>from __future__ import unicode_literals, division, absolute_import

import copy
import logging

from flask import jsonify, request

from flexget.api import api, APIResource
from flexget.plugins.api.movie_queue import empty_response
from flexget.plugins.list.movie_list import PluginMovieList as ml

log = logging.getLogger('movie_list')

movie_list_api = api.namespace('movie_list', description='Movie List operations')

default_error_schema = {
    'type': 'object',
    'properties': {
        'status': {'type': 'string'},
        'message': {'type': 'string'}
    }
}

default_error_schema = api.schema('default_error_schema', default_error_schema)

base_movie_entry = {
    'type': 'object',
    'properties': {
        'title': {'type': 'string'},
        'url': {'type': 'string'},
        'movie_name': {'type': 'string'},
        'movie_year': {'type': 'integer'}
    },
    'additionalProperties': True,
    'required': ['url'],
    'anyOf': [
        {'required': ['title']},
        {'required': ['movie_name', 'movie_year']}
    ]

}

return_movie_entry = copy.deepcopy(base_movie_entry)
return_movie_entry['properties']['id'] = {'type': 'integer'}
return_movie_entry['properties']['list_name'] = {'type': 'string'}

return_movie_list = {
    'type': 'object',
    'properties': {
        'movies': {
            'type': 'array',
            'items': return_movie_entry
        },
        'number_of_movies': {'type': 'integer'},
        'list_name': {'type': 'string'}
    }
}

base_movie_entry_schema = api.schema('base_movie_entry', base_movie_entry)
return_movie_entry_schema = api.schema('return_movie_entry_schema', return_movie_entry)
movie_list_return_schema = api.schema('movie_list_return_model', return_movie_list)


@movie_list_api.route('/<string:list_name>')
@api.doc(params={'list_name': 'Name of the list'})
class MovieListAPI(APIResource):
    @api.response(code_or_apierror=200, model=movie_list_return_schema)
    def get(self, list_name, session=None):
        ''' Get Movie list entries '''
        # TODO Pagination
        movies = [dict(movie) for movie in ml.get_list(list_name)]
        return jsonify({'movies': movies,
                        'number_of_entries': len(movies),
                        'list_name': list_name})

    @api.validate(base_movie_entry_schema)
    @api.response(201, model=return_movie_entry_schema)
    @api.doc(description="This will create a new list if list name doesn't exist")
    def post(self, list_name, session=None):
        ''' Adds a movie to the list. '''
        data = request.json
        movies = ml.get_list(list_name)

        movie = movies.add(data, session=session)
        return movie, 201


@movie_list_api.route('/<string:list_name>/<int:id>/')
@api.doc(params={'list_name': 'Name of the list', 'id': 'ID of the movie'})
class MovieListIDAPI(APIResource):
    @api.response(200, model=return_movie_entry_schema)
    @api.response(404, model=default_error_schema)
    def get(self, list_name, id, session=None):
        ''' Get a specific movie ID '''
        movies = [dict(movie) for movie in ml.get_list(list_name)]
        for movie in movies:
            if movie['id'] == id:
                return movie
        return {'status': 'error',
                'message': 'could not find movie with id %d in list %s'% (id, list_name)}, 404

    @api.validate(base_movie_entry_schema)
    @api.response(200, model=return_movie_entry_schema)
    @api.response(404, model=default_error_schema)
    def put(self, list_name, id, session=None):
        ''' Edit a specific movie ID '''
        data = request.json
        movies = ml.get_list(list_name)
        resolved_movies = [dict(movie) for movie in movies]
        for resolved_movie in resolved_movies:
            if resolved_movie['id'] == id:
                movies.discard(resolved_movie)
                new_movie = movies.add(data)
                return new_movie, 201
        return {'status': 'error',
                'message': 'could not find movie with id %d in list %s'% (id, list_name)}, 404

    @api.response(200, model=empty_response)
    @api.response(404, model=default_error_schema)
    def delete(self, list_name, id, session=None):
        ''' Remove an movie from the list '''
        movies = ml.get_list(list_name)
        resolved_movies = [dict(movie) for movie in movies]
        for resolved_movie in resolved_movies:
            if resolved_movie['id'] == id:
                movies.discard(resolved_movie)
                return {}
        return {'status': 'error',
                'message': 'could not find movie with id %d in list %s'% (id, list_name)}, 404
{'fraction_non_alphanumeric': 0.13558413719185422, 'fraction_numerical': 0.006832797427652733, 'mean_word_length': 3.3401162790697674, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6794348', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2274, 'n_words': 524}