예제 #1
0
def deploy(request, path, msg):
    if path is None:
        return alexa.respond(
            message="Could not prepare the deployment request to create the %s"
            % msg,
            end_session=True)
    response = dclient.put_item(
        TableName=DYNAMO_TABLE,
        Item={
            'sessionId': {
                'S': request.session_id()
            },
            'templatePath': {
                'S': path
            },
            'message': {
                'S': msg
            },
            'time': {
                'N': str(int(unixtime(datetime.now().timetuple())))
            },
            'expires': {
                'N': '3600'
            }
        })
    return alexa.respond(
        message="Please confirm you would like to deploy the %s" % msg)
예제 #2
0
def housing_numbers(request):
    year = request.get_slot_value('year')
    logger.info('apartments')
    logger.info(request.get_slot_map())
    return alexa.respond(
        '''
        <speak>
        the number of apartments built during that year in Stockholm, is <say-as interpret-as="cardinal">%s</say-as>
        </speak>
        ''' % (car_accidents.get_num_apartments_stockholm(year)),
    )
예제 #3
0
def check_scores(request):
    scores = topscores()
    if not scores:
        return alexa.respond(message="There are no current top scores.",
                             end_session=True)

    if len(scores) == 1:
        return alexa.respond(
            message="The winner is %s with a score of %d where they %s." %
            (scores[0]['username'], scores[0]['score'],
             'survived' if scores[0]['completed'] else 'died'),
            end_session=True)

    names = 'and %s.' % scores[0]['username']
    for index, item in enumerate(scores):
        if not index == 0:
            names = '%s, ' % item['username'] + names
    message = 'There are multiple winners with a score of %d where they %s. Their names are %s' % (
        scores[0]['score'], 'survived' if scores[0]['completed'] else 'died',
        names)
    return alexa.respond(message=message, end_session=True)
예제 #4
0
def water_usage_stockholm(request):
    year = request.get_slot_value('year')
    logger.info('water_usage_stockholm')
    logger.info(request.get_slot_map())
    return alexa.respond(
        '''
            <speak>
            the water consumption in Stockholm in <say-as interpret-as="date" format="y">%s</say-as>,
            is <say-as interpret-as="cardinal">%s</say-as>
            </speak>
        ''' % (year, car_accidents.get_water_usage_stockholm(year)),
        end_session=True, is_ssml=True)
예제 #5
0
def car_accidents_intent_handler(request):
    logger.info('car_accidents_intent_handler')
    logger.info(request.get_slot_map())

    city = request.get_slot_value('city')
    year = request.get_slot_value('year')

    if not city:
        return alexa.respond('Sorry, which city?')

    num_card_acc = car_accidents.get_num_accidents(year=int(year), city=city)
    logger.info('%s accidents in %s in %s', num_card_acc, city, year)

    return alexa.respond(
        '''
          <speak>
          There were
          <say-as interpret-as="cardinal">%s</say-as>
          car accidents in %s in
          <say-as interpret-as="date" format="y">%s</say-as>,
          </speak>
        ''' % (num_card_acc, city, year),
        end_session=True, is_ssml=True)
예제 #6
0
def population_intent_handler(request):
    logger.info('population_sweden_intent_handler')
    logger.info(request.get_slot_map())
    year = request.get_slot_value('year')

    return alexa.respond(
        '''
          <speak>
          in
          <say-as interpret-as="date" format="y">%s</say-as>,
          The expected population of Sweden is going to be
          <say-as interpret-as="cardinal">%s</say-as>
          </speak>
        ''' % (year, expected_population.get_expected_population(year)),
        end_session=True, is_ssml=True)
예제 #7
0
def cancel(request):
    return alexa.respond(message="Goodbye!", end_session=True)
예제 #8
0
def confirm(request):
    ''' This handler will confirm requests and execute them '''
    response = queryOnSessionKey(request)
    if response['Count'] == 0:
        return alexa.respond(
            message="I am not sure what you would like to do.",
            end_session=True)

    r_items = response['Items']
    while ('LastEvaluatedKey' in response):
        response = queryOnSessionKey(request, response['LastEvaluatedKey'])
        r_items += response['Items']

    p_items = []
    for index, item in enumerate(r_items):
        n_item = {}
        n_item['templatePath'] = item['templatePath']['S']
        n_item['message'] = item['message']['S']
        n_item['time'] = int(item['time']['N'])
        p_items.append(n_item)

    s_items = sorted(p_items, key=itemgetter('time'), reverse=True)

    s_request = s_items[0]

    try:
        stackFilter = StackStatusFilter = [
            'CREATE_COMPLETE', 'ROLLBACK_COMPLETE', 'UPDATE_COMPLETE',
            'UPDATE_ROLLBACK_COMPLETE'
        ]
        response = cclient.list_stacks(StackStatusFilter=stackFilter)
        stacks = response['StackSummaries']
        while ('NextToken' in response):
            response = cclient.list_stacks(NextToken=response['NextToken'],
                                           StackStatusFilter=stackFilter)
            stacks += response['StackSummaries']

        found = False
        for index, item in enumerate(stacks):
            if item['StackName'] == STACK_NAME:
                found = True
        if found:
            response = cclient.update_stack(
                StackName=STACK_NAME,
                TemplateURL=s_request['templatePath'],
                Parameters=[{
                    'ParameterKey': 'EnvironmentName',
                    'ParameterValue': STACK_ENVIRONNAME
                }],
                Capabilities=['CAPABILITY_IAM'])
        else:
            response = cclient.create_stack(
                StackName=STACK_NAME,
                TemplateURL=s_request['templatePath'],
                Parameters=[{
                    'ParameterKey': 'EnvironmentName',
                    'ParameterValue': STACK_ENVIRONNAME
                }],
                Capabilities=['CAPABILITY_IAM'])
    except Exception as e:
        print str(e)
        return alexa.respond(
            message="I was unable to complete creating the %s" %
            s_request['message'],
            end_session=True)
    return alexa.respond(message="I am creating the %s" % s_request['message'],
                         end_session=True)
예제 #9
0
def default(request):
    ''' The default handler gets invoked if Alexa doesn't understand the request '''
    return alexa.respond(
        message=
        "I'm sorry. I'm afraid I can't do that. Please try another request.",
        end_session=True)
예제 #10
0
def default_handler(request):
    """ The default handler gets invoked if no handler is set for a request type """
    return alexa.respond(get_pool_weather_handler(request))
예제 #11
0
def stop_intent_handler(request):
    logger.info('stop_intent_handler')
    return alexa.respond('Okay.', end_session=True)
예제 #12
0
def help_intent_handler(request):
    logger.info('help_intent_handler')
    return alexa.respond('You can ask me about car accidents.', end_session=True)
예제 #13
0
def session_ended_request_handler(request):
    logger.info('session_ended_request_handler')
    return alexa.respond('Goodbye.', end_session=True)
예제 #14
0
def launch_request_handler(request):
    logger.info('launch_request_handler')
    return alexa.respond('Ask me about any public data about Sweden.', end_session=True)
예제 #15
0
def default_handler(request):
    logger.info('default_handler')
    return alexa.respond("Sorry, I don't understand.", end_session=True)
예제 #16
0
def default_handler(request):
    """ The default handler gets invoked if no handler is set for a request type """
    return alexa.respond('Just ask').with_card('Hello World')
def default_handler(request):
    """ The default handler gets invoked if no handler is set for a request type """
    return alexa.respond('Just ask').with_card('Hello World')
def default_handler(request):
    """ The default handler gets invoked if no handler is set for a request type """
    return alexa.respond('Starte mit Spiele meine Erinnerungen ab.')