Пример #1
0
def collect():
    if current_user.is_authenticated:

        form = StockForm()

        if form.validate_on_submit():
            try:
                start = datetime.datetime(int(form.start_year.data),
                                          int(form.start_month.data),
                                          int(form.start_date.data))
                end = datetime.datetime(int(form.end_year.data),
                                        int(form.end_month.data),
                                        int(form.end_date.data))
                stock = form.search_stock.data
                result = web.DataReader(stock, 'yahoo', start, end)
                result_info.update(result)
                stocl_info.append(form.search_stock.data)
                start_year.append(form.start_year.data)
                start_month.append(form.start_month.data)
                start_date.append(form.start_date.data)
                end_year.append(form.end_year.data)
                end_month.append(form.end_month.data)
                end_date.append(form.end_date.data)
            except:
                flash('Type error!', 'warning')
                return redirect(url_for('stock.collect'))

            return render_template('stock_result.html', data=result.to_html())
    else:
        flash('You need login!', 'warning')
        return redirect(url_for('main.home'))
    return render_template('stock.html', form=form)
Пример #2
0
def collect():
    if current_user.is_authenticated:
        form = StockForm()
        if form.validate_on_submit():
            try:
                start = datetime.datetime(int(form.start_year.data), int(form.start_month.data), int(form.start_date.data))
                end = datetime.datetime(int(form.end_year.data), int(form.end_month.data), int(form.end_date.data))
                stock = form.search_stock.data
                result = web.DataReader(stock, 'yahoo', start, end)
                # df = pd.DataFrame(column.values, columns=['選擇', '股票代號', '時間', '成交', '買進', '賣出', '漲跌', '張數', '昨收', '開盤', '最高', '最低'])
                session['result'] = result.to_json()

            except Exception as e:
                print('error====', e)
                flash('Type error!', 'warning')
                return redirect(url_for('stock.collect'))

            return render_template('stock_result.html', data=result.to_html())
    else:
        flash('You need login!', 'warning')
        return redirect(url_for('main.home'))
    return render_template('stock.html', form=form)