def doserach() -> 'html': @copy_current_request_context def log_request(req: 'Flask_Request', results: str) -> None: """Log details of the web request and the results.""" with UseDatabase(app.config['dbconfig']) as cursor: _SQL_INSERT = """insert into log_table (phrase, letters, ip, browser_string, results) values (?, ?, ?, ?, ?)""" cursor.execute(_SQL_INSERT, (req.form['phrase'], req.form['letter'], req.remote_addr, req.user_agent.browser, results,)) phrase = request.form['phrase'] letter = request.form['letter'] title = 'Here are your results:' results = str(vsearch.search4letter(phrase, letter)) try: #log_request(request, results) t = Thread(target=log_request, args=(request, results)) t.start() except Exception as err: print('*****Login failed with the error: ', str(err)) return render_template('results.html', the_title=title, the_phrase=phrase, the_letters=letter, the_results=results, )
def search4() -> 'html': phrase=request.form['phrase'] letters=request.form['letters'] the_title="Here Is The Result" result=str(search4letter(phrase,letters)) log_request(request,result) return render_template('result.html', the_phrase=phrase, the_letters=letters, the_title=the_title, the_results=result)
def do_search() -> 'html': phrase = request.form['phrase'] letters = request.form['letters'] title = 'Here are your results' results = str(search4letter(phrase, letters)) log_request(request, results) return render_template( 'results.html', the_phrase=phrase, the_letters=letters, the_title=title, the_results=results, )
def do_search() -> 'html': @copy_current_request_context def log_request(req: 'flask_request', res: str) -> None: '''журналирует веб запрос и возвращаемые результаты''' try: sleep(10) 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, )) except ConnectionError as err: print('Ваша база данных подключена?: ', str(err)) except CredentialsError as err: print('Ошибка логин/пароль. Error: ', str(err)) except SQLError as err: print('Ваш запрос SQL правильный? Error:', str(err)) except Exception as err: print('Ошибка типа: ', str(err)) phrase = request.form['phrase'] letters = request.form['letters'] title = 'Вот ваши результаты:' results = str(search4letter(phrase, letters)) try: thread = Thread(target=log_request, args=(request, results)) thread.start() except Exception as err: print('Ошибка при сохранении в базу: ', str(err)) return render_template( 'results.html', the_title=title, the_phrase=phrase, the_letters=letters, the_results=results, )
def do_search() -> str: return str(vsearch.search4letter('woobly doobly doo', 'everythng'))