Пример #1
0
def _get_stocks(ticker_list):
    stocks = []
    for ticker in ticker_list:
        data = Stock.get_last(ticker)
        if data is None:
            logger.error(
                f"Watchlist contains unknown stock ticker: " + str(ticker))
            raise UnknownStockError(ticker)
        stocks.append(data)

    return stocks
Пример #2
0
def handle_get_stock_price_intent(request):
    """
    Generate response to intent type WhatsTheStockPriceIntent with the current price of the added ticker.
    :type request AlexaRequest
    :return: JSON response including stock price
    """
    ticker = request.get_slot_value(slot_name="stockTicker").upper()

    # Query DB for stock data
    stock = Stock.get_last(ticker)

    if type(stock) is NoneType:
        logger.error(f"There was an error getting data for {ticker}")
        message = strings.INTENT_STOCK_PRICE_MSG_FAIL.format(ticker)
        response = ResponseBuilder.create_response(request, message=message)
    else:
        message = strings.INTENT_STOCK_PRICE_MSG.format(stock['ticker'], stock['price'])
        response = ResponseBuilder.create_response(request, message=message) \
            .set_session('stockTicker', stock['ticker'])

    reprompt_message = strings.INTENT_GENERAL_REPROMPT

    return response.with_reprompt(reprompt_message)