Example #1
0
def do_search() -> 'html':
    @copy_current_request_context
    def log_request(req: 'flask_request', res: str) -> None:
        sleep(15)  # This makes log_request really slow...
        with UseDatabase(app.config['dbconfig']) as cursor:
            _SQL = """INSERT INTO log
                        (phrase, letters, ip, browser_string, results) VALUES 
                        (%s, %s, %s, %s, %s)"""
            cursor.execute(_SQL, (
                req.form['phrase'],
                req.form['letters'],
                req.remote_addr,
                req.user_agent.browser,
                res,
            ))

    phrase = request.form['phrase']
    letters = request.form['letters']
    title = 'Here are your results:'
    results = str(search4letters(phrase, letters))
    try:
        t = Thread(target=log_request, args=(request, results))
        t.start()
    except Exception as err:
        print('***** Logging failed with this error:', str(err))

    return render_template(
        'results.html',
        the_phrase=phrase,
        the_letters=letters,
        the_title=title,
        the_results=results,
    )
Example #2
0
def do_search() -> 'html':
    phrase = request.form['phrase']
    letters = request.form['letters']
    title = 'Here are your results:'
    results = str(search4letters(phrase, letters))
    return render_template(
        'results.html',
        the_phrase=phrase,
        the_letters=letters,
        the_title=title,
        the_results=results,
    )
def do_search() -> 'html':
    phrase = request.form['phrase']
    letters = request.form['letters']
    title = 'Here are your results:'
    results = str(search4letters(phrase, letters))
    try:
        log_request(request, results)
    except Exception as err:
        print('***** Logging failed with this error:', str(err))

    return render_template(
        'results.html',
        the_phrase=phrase,
        the_letters=letters,
        the_title=title,
        the_results=results,
    )