<commit_before>from functools import wraps
from flask import Flask, request, redirect
from models import Memegen, Slack


app = Flask(__name__)


def ssl_required(fn):
    @wraps(fn)
    def decorated_view(*args, **kwargs):
        if not any([app.debug, request.is_secure, request.headers.get("X-Forwarded-Proto", "") == "https"]):
            return redirect(request.url.replace("http://", "https://"))
        else:
            return fn(*args, **kwargs)

    return decorated_view


@ssl_required
@app.route("/")
def meme():
    meme = Memegen()
    slack = Slack()

    token = request.args["token"]

    if token != slack.SLASH_COMMAND_TOKEN:
        return "Unauthorized."

    text = request.args["text"]

    if text[:9] == "templates":
        return meme.get_help()

    try:
        template, top, bottom = meme.parse_text_into_params(text)
    except:
        return "Your syntax should be in the form `/meme [template]; [top]; [bottom];. Type `/meme templates` to see valid templates."

    valid_templates = [x["name"] for x in meme.get_templates()]

    if template not in valid_templates:
        return "That template doesn't exist. Type `/meme templates` to see valid templates."<commit_msg>Memegen.parst_text_into_params isn't going to throw an exception.<commit_after>from functools import wraps
from flask import Flask, request, redirect
from models import Memegen, Slack


app = Flask(__name__)


def ssl_required(fn):
    @wraps(fn)
    def decorated_view(*args, **kwargs):
        if not any([app.debug, request.is_secure, request.headers.get("X-Forwarded-Proto", "") == "https"]):
            return redirect(request.url.replace("http://", "https://"))
        else:
            return fn(*args, **kwargs)

    return decorated_view


@ssl_required
@app.route("/")
def meme():
    meme = Memegen()
    slack = Slack()

    token = request.args["token"]

    if token != slack.SLASH_COMMAND_TOKEN:
        return "Unauthorized."

    text = request.args["text"]

    if text[:9] == "templates":
        return meme.get_help()

    template, top, bottom = meme.parse_text_into_params(text)

    valid_templates = [x["name"] for x in meme.get_templates()]

    if template not in valid_templates:
        return "That template doesn't exist. Type `/meme templates` to see valid templates."
{'fraction_non_alphanumeric': 0.1327854671280277, 'fraction_numerical': 0.0008650519031141869, 'mean_word_length': 3.2208029197080292, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '602148', 'n_tokens_mistral': 724, 'n_tokens_neox': 700, 'n_words': 200}