def get(self):
        if self.request.get('type') == "web":
            stockName = self.request.get('sname')
            selected_date = self.request.get('sdate')
            
            self.response.write(web_index.show_html(stockName, selected_date))
            
        elif self.request.get('type') == "data":
            self.response.write("data")
            
        elif self.request.get('type') == "app":
            self.response.write("app")
        
        elif self.request.get('type') == "candlechart":
            code = self.request.get('code')
            start_date = datetime.strptime(self.request.get('start_date'), "%Y-%m-%d")
            end_date = datetime.strptime(self.request.get('end_date'), "%Y-%m-%d")

            logger.info('Draw CandleStick Chart, code=%s, start time=%s, end time=%s' % (code, start_date.strftime("%Y/%m/%d"), end_date.strftime("%Y/%m/%d")))
            record_text = []
            for record in db_stock_price.get_price(code, start_date=start_date, end_date=end_date):
                record_text.append([record.date_time.strftime("%m/%d"), record.low_price, record.open_price, record.close_price, record.high_price])
            output = cStringIO.StringIO()
            print >>output, record_text
            contents = output.getvalue()
            #print contents
            
            self.response.write(web_stock_candlechart.show_html(contents))
        else:
            self.response.write("Please specify a type!!<br />")
            self.response.write("<form>post-type:<input value='web' name='type'><input type='submit' value='submit'></form>")
Ejemplo n.º 2
0
def show_content(stockName, selected_date):
    selected_date = datetime.strptime(selected_date,'%Y-%m-%d')
    
    price_list = []
    result = db_stock_price.get_price(stockName, selected_date, selected_date)
    if result:
        for record in result:
            price_list.append(str(record.close_price))
            
        getStockPrice = "<br> yahoo get_price() sample: [" + stockName + "] $"
        getStockPrice += ",".join(price_list)
    else:
        getStockPrice = "<br> Can't not find record on selected date!"

    return getStockPrice