Exemplo n.º 1
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In BuyIntentHandler")

        # Get user's input for company slot from Alexa
        company = util.get_resolved_value(
            handler_input.request_envelope.request, "company")
        quantity = util.get_resolved_value(
            handler_input.request_envelope.request, "quantity")

        # Get stock symbol of company
        s = util.get_stock_symbol(company)
        symbol = s['ResultSet']['Result'][0]['symbol']

        # Get stock price using symbol
        price = util.get_stock_price(symbol)

        # Create message for stock bought
        message = data.BUY_MESSAGE.format(quantity, company, price,
                                          datetime.today())

        # Return buy response
        handler_input.response_builder.speak(message).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 2
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In GetQuoteHandler")

        # Get user's input for company slot from Alexa
        company = util.get_resolved_value(
            handler_input.request_envelope.request, "company")

        # Get stock symbol of company
        s = util.get_stock_symbol(company)
        symbol = s['ResultSet']['Result'][0]['symbol']

        # Get quote using retrieved symbol
        quote = util.get_stock_quote(symbol)

        logger.debug("Got stock quote for {}".format(company))

        # Format values from quote
        open_price = util.get_decimal_value(quote['open'])
        latest_price = util.get_decimal_value(quote['latestPrice'])
        change_percent = util.get_decimal_value(quote['changePercent'])

        # Create message for quote
        message = data.QUOTE_MESSAGE.format(
            quote['symbol'], quote['companyName'], quote['sector'],
            quote['primaryExchange'], open_price, latest_price, change_percent)

        # Return message for quote
        handler_input.response_builder.speak(message).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 3
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In AddDietaryRequirementsIntentHandler")
        person = util.get_resolved_value(
            handler_input.request_envelope.request, "person")
        person_say = person + " is"
        if person is None:
            person = "you"
            person_say = "you are"
        value = util.get_resolved_value(handler_input.request_envelope.request,
                                        "dietary_req")
        speech = ("Okay. I'll remember that {} {}.").format(person_say, value)

        ddb.addDietaryReq(person, value)

        handler_input.response_builder.speak(speech).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 4
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In AddDislikedRestaurantIntentHandler")
        person = util.get_resolved_value(
            handler_input.request_envelope.request, "person")
        if person is None:
            person = "you"
        value = util.get_resolved_value(handler_input.request_envelope.request,
                                        "restaurant")
        if value is None:
            value = ddb.getLastRestaurant(person)
        speech = ("Okay. I'll remember that {} disliked {}.").format(
            person, value)

        ddb.addDislikedRestaurant(person, value)

        handler_input.response_builder.speak(speech).set_should_end_session(
            False)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In FaqIntent")
        housing = util.get_resolved_value(
            handler_input.request_envelope.request, "housing")
        alumni = util.get_resolved_value(
            handler_input.request_envelope.request, "alumni")
        attribute_manager = handler_input.attributes_manager
        session_attr = attribute_manager.session_attributes
        if (housing is not None):
            session_attr["class"] = "housing"
        elif (alumni is not None):
            session_attr["class"] = "alumni"
        else:
            session_attr["class"] = "counseling"

        speech = "Ok... Thank you for your response... Now you can ask me your queries with hot keyword... 'tell me' "
        handler_input.response_builder.speak(speech).ask(speech)
        return handler_input.response_builder.response
Exemplo n.º 6
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        global place
        logger.info("In AddCityIntentHandler")
        place = util.get_resolved_value(
            handler_input.request_envelope.request, "city")
        if place is None:
            place = "NOWHERE"

        speech = ("You are in {}. I will record that.").format(place)

        handler_input.response_builder.speak(speech).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 7
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In TrendStatsHandler")

        # Get user's input for company slot from Alexa
        company = util.get_resolved_value(
            handler_input.request_envelope.request, "company")

        # Get stock symbol of company
        s = util.get_stock_symbol(company)
        symbol = s['ResultSet']['Result']['0']['symbol']

        # Get trend stats using symbol
        trend_stats = util.get_stock_trendstats(symbol)

        logger.debug("Got trend stats of {}".format(company))

        # Format trend_stats values
        week52_high = util.get_decimal_value(trend_stats['week52high'])
        week52_low = util.get_decimal_value(trend_stats['week52low'])
        week52_change = util.get_decimal_value(trend_stats['week52change'])
        ebitda = util.get_decimal_value(trend_stats['EBITDA'])
        day200_mAvg = util.get_decimal_value(trend_stats['day200MovingAvg'])
        day50_mAvg = util.get_decimal_value(trend_stats['day50MovingAvg'])
        year5_change = util.get_decimal_value(
            trend_stats['year5ChangePercent'])
        year2_change = util.get_decimal_value(
            trend_stats['year2ChangePercent'])
        year1_change = util.get_decimal_value(
            trend_stats['year1ChangePercent'])
        month6_change = util.get_decimal_value(
            trend_stats['month6ChangePercent'])
        month3_change = util.get_decimal_value(
            trend_stats['month3ChangePercent'])
        month1_change = util.get_decimal_value(
            trend_stats['month1ChangePercent'])
        day5_change = util.get_decimal_value(trend_stats['day5ChangePercent'])

        # Create key stats message
        message = data.TRENDSTATS_MESSAGE.format(
            trend_stats['companyName'], week52_high, week52_low, week52_change,
            ebitda, day200_mAvg, day50_mAvg, year5_change, year2_change,
            year1_change, month6_change, month3_change, month1_change,
            day5_change)

        # Return trend stats response
        handler_input.response_builder.speak(message).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 8
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In SearchRestaurantsWithFriendIntentHandler")
        attribute_manager = handler_input.attributes_manager
        _ = handler_input.attributes_manager.request_attributes["_"]
        session_attr = attribute_manager.session_attributes

        place = ddb.getLocation()
        if (place == "NOWHERE"):
            speech = "I don't know where you are. "
        else:
            person = util.get_resolved_value(
                handler_input.request_envelope.request, "person")

            req = ddb.getDietaryReq(person)
            if len(req) != 0:
                dietaryList = req
                if len(dietaryList) > 1:
                    dietaryList.insert(len(dietaryList) - 1, "and")

                search_result = util.search(data.API_HOST, data.SEARCH_PATH,
                                            data.API_KEY, place,
                                            req)['businesses']
                speech = "{} is {} ".format(person, dietaryList)
            else:
                search_result = util.search(data.API_HOST, data.SEARCH_PATH,
                                            data.API_KEY, place)['businesses']
                speech = ""

            session_attr["num_of_search"] = 0
            session_attr["curr_restaurant"] = search_result.pop(
                random.randrange(0, 9, 1))
            session_attr["rest_restaurants"] = search_result

            # logger.info(session_attr["curr_restaurant"])
            # logger.info(session_attr["rest_restaurants"])

            speech = (
                speech + "I found a place nearby, called {}. "
                "Do you want more information about it?  "
                "Or do you want another suggestion? "
                "<say-as interpret-as='interjection'>bon appetit</say-as>".
                format(session_attr["curr_restaurant"]["name"]))
        handler_input.response_builder.speak(speech).set_should_end_session(
            False)

        return handler_input.response_builder.response
Exemplo n.º 9
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In GetDislikedRestaurantsIntentHandler")

        person = util.get_resolved_value(
            handler_input.request_envelope.request, "person")
        if person is None:
            person = "you"
        value = ddb.getDislikedRestaurants(person)
        if len(value) != 0:
            speech = ("{} disliked {}.").format(person, value)
        else:
            speech = ("None that I know of.")

        handler_input.response_builder.speak(speech).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 10
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In AttractionIntentHandler")
        distance = util.get_resolved_value(
            handler_input.request_envelope.request, "distance")
        if distance is None:
            distance = 200

        attraction = random.choice(
            util.get_attractions_by_distance(data.CITY_DATA, distance))
        speech = "Try {}, which is {}. {}. Have fun!!".format(
            attraction["name"], "right downtown" if attraction["distance"]
            == "0" else "{} miles away".format(attraction["distance"]),
            attraction["description"])

        handler_input.response_builder.speak(speech).set_should_end_session(
            True)
        return handler_input.response_builder.response
Exemplo n.º 11
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In GetDietaryRequirementsIntentHandler")

        person = util.get_resolved_value(
            handler_input.request_envelope.request, "person")
        person_say = person + " is"
        if person is None:
            person = "you"
            person_say = "you are"
        value = ddb.getDietaryReq(person)
        if len(value) != 0:
            speech = ("{} {}").format(person_say, value)
        else:
            speech = ("None that I know of.")

        handler_input.response_builder.speak(speech).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 12
0
    def handle(self, handler_input):
        city = util.get_resolved_value(handler_input.request_envelope.request,
                                       "city")

        stations = get_locational_stations(city)
        logger.info(stations)
        speech = f"Here are {min(3, len(stations))} stations in {city}: "

        logger.info(min(len(stations['hits']), 3))

        for hitList in range(min(len(stations['hits']), 3)):
            try:
                speech += stations['hits'][hitList]['pronouncements'][0][
                    'utterance'] + ', '
            except:
                speech += stations['hits'][hitList]['name'] + ', '

        handler_input.response_builder.speak(speech)
        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In FaqIntent")
        query = util.get_resolved_value(handler_input.request_envelope.request,
                                        "query")
        attribute_manager = handler_input.attributes_manager
        session_attr = attribute_manager.session_attributes
        _ = attribute_manager.request_attributes["_"]
        try:
            className = session_attr["class"]
        except Exception:
            className = "housing"
        answer = util.get_answer({
            "query": query,
            "class": className
        }, data.MY_API)

        speech = answer
        handler_input.response_builder.speak(speech).set_should_end_session(
            True)
        return handler_input.response_builder.response
Exemplo n.º 14
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In GetKeyStatHandler")

        # Get user's input for company slot from Alexa
        company = util.get_resolved_value(
            handler_input.request_envelope.request, "company")

        # Get stock symbol of company
        s = util.get_stock_symbol(company)
        symbol = s['ResultSet']['Result'][0]['symbol']

        # Get key stats data using symbol
        key_stats = util.get_stock_keystats(symbol)

        logger.debug("Got key stats of {}".format(company))

        # Format values from key_stats
        week52_high = util.get_decimal_value(key_stats['week52high'])
        week52_low = util.get_decimal_value(key_stats['week52low'])
        week52_change = util.get_decimal_value(key_stats['week52change'])
        latest_EPS = util.get_decimal_value(key_stats['latestEPS'])
        peRatio_high = util.get_decimal_value(key_stats['peRatioHigh'])
        peRatio_low = util.get_decimal_value(key_stats['peRatioLow'])
        price_sales = util.get_decimal_value(key_stats['priceToSales'])
        price_book = util.get_decimal_value(key_stats['priceToBook'])
        day200_mAvg = util.get_decimal_value(key_stats['day200MovingAvg'])
        day50_mAvg = util.get_decimal_value(key_stats['day50MovingAvg'])

        # Create message for key stats
        message = data.KEYSTATS_MESSAGE.format(
            key_stats['companyName'], week52_high, week52_low, week52_change,
            latest_EPS, key_stats['latestEPSDate'], peRatio_high, peRatio_low,
            price_sales, price_book, day200_mAvg, day50_mAvg)

        # Return key stats response
        handler_input.response_builder.speak(message).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 15
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In GetNewsHandler")

        # Get user's input for company slot from Alexa
        company = util.get_resolved_value(
            handler_input.request_envelope.request, "company")

        # Get stock symbol of company
        s = util.get_stock_symbol(company)
        symbol = s['ResultSet']['Result'][0]['symbol']

        # Get stock news using symbol
        news = util.get_stock_news(symbol)
        logger.debug("Got stock news of {}".format(company))

        # Get tone analysis using news summary
        tone_analysis = util.get_tone_analysis(news['summary'])
        json_tones = json.loads(tone_analysis)
        logger.debug("Got tone analysis of {}".format(company))

        # Create message for tone
        tone_message = ''
        for tone in json_tones['document_tone']['tones']:
            percent_confidence = util.get_decimal_value(tone['score'] * 100)
            tone_name = tone['tone_name']
            tone_message += data.TONE_MESSAGE.format(percent_confidence,
                                                     tone_name)

        # Create message for news
        message = data.NEWS_MESSAGE.format(news['headline'], news['source'],
                                           news['datetime'], tone_message)

        # Return message for news
        handler_input.response_builder.speak(message).set_should_end_session(
            False)
        return handler_input.response_builder.response
Exemplo n.º 16
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In GetPriceHandler")

        # Get user's input for company slot from Alexa
        company = util.get_resolved_value(
            handler_input.request_envelope.request, "company")

        # Get stock symbol of company
        s = util.get_stock_symbol(company)
        symbol = s['ResultSet']['Result'][0]['symbol']

        # Get stock price using symbol
        price = util.get_stock_price(symbol)

        logger.debug("Got price of {}".format(company))

        # Create message for price
        message = data.PRICE_MESSAGE.format(company, price)

        # Return price response
        handler_input.response_builder.speak(message).set_should_end_session(
            False)
        return handler_input.response_builder.response