def hello_world(): form = SearchForm() parsed_category_list = None parsed_result_list = None if form.validate_on_submit(): result = es.search(index='schedule_overtime*', body={ "from": 0, "size": 10000, "query": { "query_string": { "query": "chain:" + form.data['chain'] + "* org:" + form.data['org'] + "*", "default_operator": "AND" } } }) result_list = result['hits']['hits'] parsed_result_list = [] parsed_category_list = result['hits']['hits'][0]['_source'].keys() for i in result_list: for k, v in i.items(): if k == u'_source': parsed_result_list.append(v.values()) return render_template('result.html', form=form, the_category=parsed_category_list, the_result=parsed_result_list)
def search(): # Форма поиска по записям form = SearchForm() # При загрузке страницы if request.method == 'GET': return render_template('search_form.html', form=form, message='По вашему запросу ничего не найдено!') # Поиск по записям if form.validate_on_submit(): # Создание сессии подключения к БД session = db_session.create_session() # Текст поиска text = form.search.data # Поиск notes = session.query(Notes).filter(Notes.user_id == current_user.id, Notes.title.like(f'%{text}%')) # Если записок несколько - сортировка по важности notes = sorted(notes, key=lambda x: x.is_important, reverse=True) # Ничего не найдено if not notes: return render_template( 'search_form.html', form=form, message='По вашему запросу ничего не найдено!') # Возвращение записок, удовлетворяющих условию return render_template('search_form.html', form=form, notes=notes)
def yahoo_buy_search(): form = SearchForm() # flask_wtf類中提供判斷是否表單提交過來的method,不需要自行利用request.method來做判斷 if form.validate_on_submit(): return render_template('yahoo_buy_search.html', form=form, result_div=_get_data_from_db(form.input_question.data, form.input_sort.data)) # 如果不是提交過來的表單,就是GET,這時候就回傳yahoo_buy_search.html網頁 return render_template('yahoo_buy_search.html', form=form)
def egbot(): bfx = BitfinexREST() bfx.load_key('.key/read-key') form = SearchForm() # TODO add form functionality to select crypto and dynamically update list egbot_result = None egbot_header = None active_summary = None summary_header = None position = None position_header = None ticker = None ticker_header = None symbol = None inactive_summary = None inactive_summary_header = None dao = EgbotDAO() trials_dict = dao.get_all_trials_by_crypto() trials_list = [] for k, v in trials_dict.items(): for trial in v: str_trial = str(trial) str_trial = k + ': ' + str_trial trials_list.append((str_trial, str_trial)) form.trial.choices = trials_list if form.validate_on_submit(): crypto = form.data['trial'][0:6] trial_string = form.data['trial'][8:] trial_datetime = datetime.strptime(trial_string, '%Y-%m-%d %H:%M:%S.%f') orders = dao.get_order_data_for_trial(crypto, trial_datetime) egbot_header = orders[0].keys() egbot_result = [list(x.values()) for x in orders] for x in egbot_result: x[2] = datetime.utcfromtimestamp(float(x[2])) active_positions = bfx.get_active_positions(crypto) active_summary, inactive_summary = bfx.get_summary( egbot_result, active_positions, crypto) summary_header = active_summary.keys() active_summary = list(active_summary.values()) inactive_summary_header = inactive_summary.keys() inactive_summary = list(inactive_summary.values()) if active_positions: position_header = active_positions[0].keys() position = [list(x.values()) for x in active_positions] tick = bfx.get_ticker(crypto) ticker = list(tick.values()) ticker_header = list(tick.keys()) symbol = crypto.upper() symbol = symbol[0:3] return render_template('base.html', form=form, the_egbot_header=egbot_header, the_egbot_result=egbot_result, the_summary_header=summary_header, the_summary=active_summary, the_inactive_summary_header=inactive_summary_header, the_inactive_summary=inactive_summary, the_position_header=position_header, the_position=position, the_ticker=ticker, the_ticker_header=ticker_header, the_ticker_symbol=symbol)