def remove_movie(): id = param_helpers.ensure_string(request.args.get('id')) # Check if actors played in other movies sparql = SPARQLWrapper(SPARQL_ENDPOINT) sparql.setQuery(famc.QUERY.format(id=id)) actors_df = query_and_get_df(sparql) # Remove movie sparql = SPARQLWrapper(SPARQL_UPDATE_ENDPOINT) sparql.method = 'POST' sparql.setQuery(dm.QUERY.format(id=id)) sparql.query() # Remove actors actors_to_remove = actors_df[actors_df['count'] == 1]['actor'].values if len(actors_to_remove) > 0: actor_ids_str = " ".join("(<" + actors_to_remove + ">)") sparql = SPARQLWrapper(SPARQL_UPDATE_ENDPOINT) sparql.method = 'POST' sparql.setQuery(da.QUERY.format(actor_ids=actor_ids_str)) sparql.query() return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }
def my_movies_by_actor(): actor = param_helpers.ensure_string(request.args.get('actor')) limit = request.args.get('limit', 20, int) offset = request.args.get('offset', 0, int) actor = actor.replace("'", r"\'") sparql = SPARQLWrapper(SPARQL_ENDPOINT) sparql.setQuery(mmiba.QUERY.format(actor=actor, limit=limit, offset=offset)) movie_id_df = query_and_get_df(sparql) return jsonify(get_my_movies_and_actors(movie_id_df))
def my_movies(): movie_name = param_helpers.ensure_string(request.args.get('movie_name'), None) year = request.args.get('year', None, int) limit = request.args.get('limit', 20, int) offset = request.args.get('offset', 0, int) movie_name = None if movie_name == None else movie_name.replace("'", r"\'") sparql = SPARQLWrapper(SPARQL_ENDPOINT) sparql.setQuery( mmidbm.QUERY.format(title_filter=mmidbm.TITLE_FILTER.format( movie_name=movie_name) if movie_name else '', year_filter=mmidbm.YEAR_FILTER.format( year=year) if type(year) is int else '', limit=limit, offset=offset)) movie_id_df = query_and_get_df(sparql) return jsonify(get_my_movies_and_actors(movie_id_df))