Beispiel #1
0
import os

# Configuration
app = flask.Flask('conceptnet5_web')
STATIC_PATH = os.environ.get('CONCEPTNET_WEB_STATIC',
                             os.path.join(app.root_path, 'static'))
TEMPLATE_PATH = os.environ.get('CONCEPTNET_WEB_TEMPLATES',
                               os.path.join(app.root_path, 'templates'))
app.config['RATELIMIT_ENABLED'] = os.environ.get(
    'CONCEPTNET_RATE_LIMITING') == '1'

app.config.update({
    'template_folder': TEMPLATE_PATH,
    'static_folder': STATIC_PATH
})
for filter_name, filter_func in FILTERS.items():
    app.jinja_env.filters[filter_name] = filter_func
limiter = Limiter(app, global_limits=["600 per minute", "6000 per hour"])
application = app  # for uWSGI


def get_int(args, key, default, minimum, maximum):
    strvalue = args.get(key, default)
    try:
        value = int(strvalue)
    except ValueError:
        value = default
    return max(minimum, min(maximum, value))


# Lookup: match any path starting with /a/, /c/, /d/, /r/, or /s/
Beispiel #2
0
from flask_limiter import Limiter
import os


# Configuration

WORKING_DIR = os.getcwd()
STATIC_PATH = os.environ.get('CONCEPTNET_WEB_STATIC', os.path.join(WORKING_DIR, 'static'))
TEMPLATE_PATH = os.environ.get('CONCEPTNET_WEB_TEMPLATES', os.path.join(WORKING_DIR, 'templates'))

app = flask.Flask(
    'conceptnet5_web',
    template_folder=TEMPLATE_PATH,
    static_folder=STATIC_PATH
)
for filter_name, filter_func in FILTERS.items():
    app.jinja_env.filters[filter_name] = filter_func
limiter = Limiter(app, global_limits=["600 per minute", "6000 per hour"])


def get_int(args, key, default, minimum, maximum):
    strvalue = args.get(key, default)
    try:
        value = int(strvalue)
    except ValueError:
        value = default
    return max(minimum, min(maximum, value))


# Lookup: match any path starting with /a/, /c/, /d/, /r/, or /s/
# @app.route('/<any(a, c, d, r, s):top>/<path:query>')