def post(self):
        monthStr = cgi.escape(self.request.get("month"))
        yearStr = cgi.escape(self.request.get("year"))
        amountStr = cgi.escape(self.request.get("amount"))
        tickersStr = cgi.escape(self.request.get("tickers"))
        month = int(monthStr)
        year = int(yearStr)
        amount = int(amountStr)

        tickersList = tickersStr.split(",")
        tickerToDatepriceMap = {}
        tickerToMaxDay = {}
        tickerToMinDay = {}
        tickerToAvg = {}
        for ticker in tickersList:
            data = InvestmentHelper.getCSVPriceData(month, year, 1, ticker)
            dateToPrice = InvestmentHelper.mapDateToClosePrice(data)
            count = 0
            dayOfMToShares = self.processDataToMapOfDayOfMonthToShares(
                month, year, amount, dateToPrice)
            tickerToDatepriceMap[ticker] = dayOfMToShares
            minDay = self.getKeyWithMinValue(dayOfMToShares)
            maxDay = self.getKeyWithMaxValue(dayOfMToShares)
            tickerToMinDay[ticker] = minDay
            tickerToMaxDay[ticker] = maxDay
            tickerToAvg[ticker] = self.getAvg(dayOfMToShares)

        template_values = {
            "amount": amount,
            "tickers": tickersList,
            "month": month,
            "year": year,
            "tickerToDayPrice": tickerToDatepriceMap,
            "tickerToMinDay": tickerToMinDay,
            "tickerToMaxDay": tickerToMaxDay,
            "tickerToAvg": tickerToAvg,
        }

        template = JINJA_ENVIRONMENT.get_template(
            "static/templates/dateTables.html")

        self.response.write(template.render(template_values))
  def get(self):
    stocksLastUpdate = StockUpdateDate.all();
    stocks = stocksLastUpdate.run();
    # find all tickers that we need to update
    for s in stocks:
	    currDate = s.date;
	    currDate = currDate;
	    # get the closing price data and create map of date to price
	    csvdata = InvestmentHelper.getCSVPriceData(startMonth=currDate.month, startYear=currDate.year, startDay=currDate.day, ticker=s.ticker);
	    dateToPrice = InvestmentHelper.mapDateToClosePrice(csvdata);
	    # for each date, add to stockPrice
	    for d in dateToPrice:
		    if d == date.today():
			    continue;
		    keystr = s.ticker + "_" + str(d.year) + "_" + str(d.month) + "_" + str(d.day);
		    dateprice = stockPrice(ticker=s.ticker, date=d, price=Decimal(dateToPrice[d]), key_name=keystr);
		    dateprice.put();
	    s.date = date.today() - timedelta(days=3);
	    s.put();
    self.response.out.write("finished");
  def post(self):
    monthStr = cgi.escape(self.request.get("month"));
    yearStr = cgi.escape(self.request.get("year"));
    amountStr = cgi.escape(self.request.get("amount"));
    tickersStr = cgi.escape(self.request.get("tickers"));
    month = int(monthStr);
    year = int(yearStr);
    amount = int(amountStr);

    tickersList = tickersStr.split(",");
    tickerToDatepriceMap = {};
    tickerToMaxDay = {};
    tickerToMinDay = {};
    tickerToAvg = {};
    for ticker in tickersList:
      data = InvestmentHelper.getCSVPriceData(month, year, 1, ticker);
      dateToPrice = InvestmentHelper.mapDateToClosePrice(data);
      count = 0;
      dayOfMToShares = self.processDataToMapOfDayOfMonthToShares(month, year, amount, dateToPrice);
      tickerToDatepriceMap[ticker] = dayOfMToShares;
      minDay = self.getKeyWithMinValue(dayOfMToShares);
      maxDay = self.getKeyWithMaxValue(dayOfMToShares);
      tickerToMinDay[ticker] = minDay;
      tickerToMaxDay[ticker] = maxDay;
      tickerToAvg[ticker] = self.getAvg(dayOfMToShares);

    template_values = {
      "amount": amount,
      "tickers": tickersList,
      "month": month,
      "year": year,
      "tickerToDayPrice": tickerToDatepriceMap,
      "tickerToMinDay": tickerToMinDay,
      "tickerToMaxDay": tickerToMaxDay,
      "tickerToAvg": tickerToAvg,
	    }
    
    template = JINJA_ENVIRONMENT.get_template("static/templates/dateTables.html")
    
    self.response.write(template.render(template_values))