@blueprint.route("/magic/<pattern>.jpg")
def image(pattern):
    """Get the first matching image."""
    # TODO: share this logic
    text = Text(pattern)

    items = []

    for template in app.template_service.all():
        ratio, path = template.match(str(text).lower())
        if not ratio:
            continue

        data = {}
        data['ratio'] = ratio
        data['image'] = route('image.get', key=template.key, path=path)

        items.append(data)

    try:
        url = max(items, key=lambda item: item['ratio'])['image']
    except __HOLE__:
        url = route('image.get', key="unknown", path="_")

    return redirect(url)
dataset/ETHPy150Open jacebrowning/memegen/memegen/routes/magic.py/image