Ejemplo n.º 1
0
def showTopList():
    date = request.args['date']
    date = date.encode('ascii') if date else datetime.today()
    # logging.error(date)
    df = cache.get('topList_%s'%date)
    # logging.error('topList_%s'%date)
    if df is None:
        df = ts.top_list(date=date)
        if df is None:
             html_tbl = u"<p>这一天没有数据</p>"
        else:
            cache.set('topList_%s'%date, df, timeout=600)
            html_tbl = df.to_html()
    return render_template('stock_topList.html', tbl=html_tbl)
Ejemplo n.º 2
0
def showOneStock(stock_id):
    start_date = request.args['start_date']
    end_date = request.args['end_date']

    df = cache.get('stock_%s_%s_%s'%(stock_id, start_date, end_date))
    html_content = None
    if df is None:
        if start_date == "" and end_date == "":
            df = ts.get_hist_data(code=str(stock_id))
        elif end_date == "":
            df = ts.get_hist_data(code=str(stock_id), start=start_date)
        else:
            df = ts.get_hist_data(code=str(stock_id), start=start_date, end=end_date)
        if df is None:
            html_content = u"<p>这一天没有数据</p>"
        else:
            cache.set('stock_%s_%s_%s'%(stock_id, start_date, end_date), df, timeout=600)

    # mondays = WeekdayLocator(MONDAY)        # major ticks on the mondays
    # alldays = DayLocator()              # minor ticks on the days
    # weekFormatter = DateFormatter('%b %d')  # e.g., Jan 12
    # dayFormatter = DateFormatter('%d')      # e.g., 12
    #
    # fig, ax = plt.subplots(dpi=160)
    # fig.subplots_adjust(bottom=0.2)
    # ax.xaxis.set_major_locator(mondays)
    # ax.xaxis.set_minor_locator(alldays)
    # ax.xaxis.set_major_formatter(weekFormatter)
    # # ax.xaxis.set_minor_formatter(dayFormatter)
    # df['plot_date'] = map(lambda x: matplotlib.dates.date2num(datetime.strptime(x.encode("ascii"), '%Y-%m-%d')), df.index.values)
    # quotes = df[['plot_date', 'open', 'high', 'low', 'close']].values.tolist()
    # candlestick_ohlc(ax, quotes, width=0.6, colorup=u'r', colordown=u'g')
    #
    # ax.xaxis_date()
    # ax.autoscale_view()
    # plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')

    # html_content = mpld3.fig_to_html(fig)
    return render_template('stock_one_stock.html', html_content=html_content, stock_id=stock_id)