Esempio n. 1
0
def get_posts_by_image(ctx, _params=None):
    auth.verify_privilege(ctx.user, 'posts:reverse_search')
    content = ctx.get_file('content', required=True)
    return {
        'exactPost':
            _serialize_post(ctx, posts.search_by_image_exact(content)),
        'similarPosts':
            [
                {
                    'distance': lookalike.distance,
                    'post': _serialize_post(ctx, lookalike.post),
                }
                for lookalike in posts.search_by_image(content)
            ],
    }
Esempio n. 2
0
def get_posts_by_image(ctx: rest.Context,
                       _params: Dict[str, str] = {}) -> rest.Response:
    auth.verify_privilege(ctx.user, 'posts:reverse_search')
    content = ctx.get_file('content')

    try:
        lookalikes = posts.search_by_image(content)
    except (errors.ThirdPartyError, errors.ProcessingError):
        lookalikes = []

    return {
        'exactPost':
        _serialize_post(ctx, posts.search_by_image_exact(content)),
        'similarPosts': [{
            'distance': lookalike.distance,
            'post': _serialize_post(ctx, lookalike.post),
        } for lookalike in lookalikes],
    }
Esempio n. 3
0
def get_posts_by_image(ctx: rest.Context,
                       _params: Dict[str, str] = {}) -> rest.Response:
    auth.verify_privilege(ctx.user, "posts:reverse_search")
    content = ctx.get_file("content")

    try:
        lookalikes = posts.search_by_image(content)
    except (errors.ThirdPartyError, errors.ProcessingError):
        lookalikes = []

    return {
        "exactPost":
        _serialize_post(ctx, posts.search_by_image_exact(content)),
        "similarPosts": [{
            "distance": distance,
            "post": _serialize_post(ctx, post),
        } for distance, post in lookalikes],
    }
Esempio n. 4
0
def get_posts_by_image(
        ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
    auth.verify_privilege(ctx.user, 'posts:reverse_search')
    content = ctx.get_file('content')

    try:
        lookalikes = posts.search_by_image(content)
    except (errors.ThirdPartyError, errors.ProcessingError):
        lookalikes = []

    return {
        'exactPost':
            _serialize_post(ctx, posts.search_by_image_exact(content)),
        'similarPosts':
            [
                {
                    'distance': lookalike.distance,
                    'post': _serialize_post(ctx, lookalike.post),
                }
                for lookalike in lookalikes
            ],
    }