def get_cube_bill_amount_intent_handler(request):
    resp = bills_api()

    try:

        if resp.status_code == 200:

            resp_dict = resp.json()

            billAmountList = []

            for bills in range(0, len(resp_dict)):

                if resp_dict[
                        'serviceType'] is not "TRACKABLE_PAY" or "DRIVER_PAY" or "MAID_PAY" or "COOK_PAY":
                    billAmountList.append(get_bill_amount_dict())

            for billAmount in billAmountList:
                speech_output = find_the_value('get_cube_bill_amount') + "for " + \
                                string_addition_bill(billAmount)

                card = alexa.create_card(title="Cube Intents",
                                         subtitle="Cube Bill Amount",
                                         content=speech_output)

                return alexa.create_response(
                    message=speech_output,
                    reprompt_message="I did not hear you",
                    end_session=False,
                    card_obj=card)

        else:

            print(resp.status_code)

            print("We couldn't connect to our server", resp.status_code)

    except requests.exceptions.ConnectionError:

        print("Connection Error! Http status Code {}".format(resp.status_code))

        sys.exit()

    except (requests.exceptions.RequestException,
            requests.exceptions.HTTPError):

        print("Ambiguous Error! Http status Code {}".format(resp.status_code))

        sys.exit()
def get_cube_mutual_funds_profit_intent_handler(request):
    resp = money_details()

    try:

        if resp.status_code == 200:

            # extracting data in json format
            resp_dict = resp.json()

            btrbankProfit = resp_dict['data']['btrbankProfit']

            wealthProfit = resp_dict['data']['wealthProfit']

            # No need to distinguish between the liquidity of these funds unless Alexa
            # user specifies if they want btrbank or wealth profit

            profit = int(btrbankProfit) + int(wealthProfit)

            speech_output = find_the_value('get_cube_profit') + profit

            card = alexa.create_card(title="Cube Intents",
                                     subtitle="Cube Mutual Funds Profit",
                                     content=speech_output)

            return alexa.create_response(message=speech_output,
                                         reprompt_message="I did not hear you",
                                         end_session=False,
                                         card_obj=card)

        else:

            print(resp.status_code)

            print("We couldn't connect to our server", resp.status_code)

    except requests.exceptions.ConnectionError:

        print("Connection Error! Http status Code {}".format(resp.status_code))

        sys.exit()

    except (requests.exceptions.RequestException,
            requests.exceptions.HTTPError):

        print("Ambiguous Error! Http status Code {}".format(resp.status_code))

        sys.exit()
def get_cube_helping_number_intent_handler(request):
    resp = money_details()

    try:

        if resp.status_code == 200:

            # extracting data in json format
            resp_dict = resp.json()

            lives_impacted = resp_dict['data']['livesImpacted']

            speech_output = find_the_value(
                'get_cube_helping_number') + lives_impacted + " people"

            card = alexa.create_card(title="Cube Intents",
                                     subtitle="Cube People Helped",
                                     content=speech_output)

            return alexa.create_response(message=speech_output,
                                         reprompt_message="I did not hear you",
                                         end_session=False,
                                         card_obj=card)
        else:

            print(resp.status_code)

            print("We couldn't connect to our server", resp.status_code)

    except requests.exceptions.ConnectionError:

        print("Connection Error! Http status Code {}".format(resp.status_code))

        sys.exit()

    except (requests.exceptions.RequestException,
            requests.exceptions.HTTPError):

        print("Ambiguous Error! Http status Code {}".format(resp.status_code))

        sys.exit()
def get_cube_mutual_funds_intent_handler(request):
    resp = money_details()

    try:

        if resp.status_code == 200:

            resp_dict = resp.json()

            total_mutual_funds = resp_dict['data']['totalFunds']

            speech_output = find_the_value(
                'get_cube_mutual_funds') + total_mutual_funds + " rupees"

            card = alexa.create_card(title="Cube Intents",
                                     subtitle="Cube Mutual Funds",
                                     content=speech_output)

            return alexa.create_response(message=speech_output,
                                         reprompt_message="I did not hear you",
                                         end_session=False,
                                         card_obj=card)

        else:

            print(resp.status_code)

            print("We couldn't connect to our server", resp.status_code)

    except requests.exceptions.ConnectionError:

        print("Connection Error! Http status Code {}".format(resp.status_code))

        sys.exit()

    except (requests.exceptions.RequestException,
            requests.exceptions.HTTPError):

        print("Ambiguous Error! Http status Code {}".format(resp.status_code))

        sys.exit()
def get_cube_expenses_intent_handler(request):
    resp = bills_api()

    try:

        if resp.status_code == 200:

            resp_dict = resp.json()

            date_time = request.get_slot_value['date_time']

            request.session['date_expenses'] = date_time

            # get the unixtime of date_time
            # I should not need to convert this to an integer value because flask-ask already
            # does that on my behalf during the conversion

            unixtime_slot = time.mktime(date_time.timetuple())

            number = int(request.get_slot_value['number'])

            request.session['number_expenses'] = number

            current_time = datetime.datetime.now()

            unixtime_current = time.mktime(current_time.timetuple())

            current_time_unix = unixtime_current + (86400 * number)

            dueDateList = []

            for resp_dict['body']['serviceType'] in range(0, len(resp_dict)):

                serviceType = resp_dict['body']['serviceType']

                if serviceType is "TRACKABLE_PAY" or "DRIVER_PAY" or "MAID_PAY" or "COOK_PAY":
                    dueDateList.append(get_expenses_dict())

            if unixtime_slot or number is not None:

                for dueDate in dueDateList:

                    for key, value in dueDate.items():

                        if unixtime_slot >= key:

                            updated_key = datetime.datetime.fromtimestamp(int(key)) \
                                .strftime('%Y-%m-%d %H:%M:%S')

                            updated_expenses_dict = {
                                updated_key: value
                                for key, value in dueDate.items()
                            }

                            dueDateList.append(updated_expenses_dict)

                            dueDateList.remove(dueDate)

                        elif current_time_unix >= key:

                            updated_key = datetime.datetime.fromtimestamp(int(key)) \
                                .strftime('%Y-%m-%d %H:%M:%S')

                            updated_expenses_dict = {
                                updated_key: value
                                for key, value in dueDate.items()
                            }

                            dueDateList.append(updated_expenses_dict)

                            dueDateList.remove(dueDate)

                        else:

                            dueDateList.remove(dueDate)

                for updated_expenses_dict in dueDateList:
                    speech_output = find_the_value('get_cube_expenses') + "is: " + \
                                    string_addition_expenses(updated_expenses_dict)

                    card = alexa.create_card(title="Cube Intents",
                                             subtitle="Cube Expenses",
                                             content=speech_output)

                    return alexa.create_response(
                        message=speech_output,
                        reprompt_message="I did not hear you",
                        end_session=False,
                        card_obj=card)

            else:

                for dueDate in dueDateList:
                    speech_output = "Your next big expense is: " + string_addition_expenses(
                        dueDate)

                    card = alexa.create_card(title="Cube Intents",
                                             subtitle="Cube Expenses",
                                             content=speech_output)

                    return alexa.create_response(
                        message=speech_output,
                        reprompt_message="I did not hear you",
                        end_session=False,
                        card_obj=card)

        else:

            print(resp.status_code)

            print("We couldn't connect to our server", resp.status_code)

    except requests.exceptions.ConnectionError:

        print("Connection Error! Http status Code {}".format(resp.status_code))

        sys.exit()

    except (requests.exceptions.RequestException,
            requests.exceptions.HTTPError):

        print("Ambiguous Error! Http status Code {}".format(resp.status_code))

        sys.exit()
def get_cube_bill_due_intent_handler(request):
    resp = bills_api()

    try:

        if resp.status_code == 200:

            resp_dict = resp.json()

            billDueList = []

            for resp_dict['body']['serviceType'] in range(0, len(resp_dict)):

                serviceType = resp_dict['body']['serviceType']

                if serviceType is not "TRACKABLE_PAY" or "DRIVER_PAY" or "MAID_PAY" or "COOK_PAY":
                    billDueList.append(get_expenses_dict())

            for billDue in billDueList:

                for key, value in billDue.items():
                    updated_key = datetime.datetime.fromtimestamp(int(key)) \
                        .strftime('%Y-%m-%d %H:%M:%S')

                    updated_bill_due_dict = {
                        updated_key: value
                        for key, value in billDue.items()
                    }

                    billDueList.append(updated_bill_due_dict)

                    billDueList.remove(billDue)

            for updated_bill_due_dict in billDueList:
                speech_output = find_the_value(
                    'get_cube_bill_due') + string_addition_expenses(
                        updated_bill_due_dict)
                card = alexa.create_card(title="Cube Intents",
                                         subtitle="Cube Bill Due",
                                         content=speech_output)

                return alexa.create_response(
                    message=speech_output,
                    reprompt_message="I did not hear you",
                    end_session=False,
                    card_obj=card)

        else:

            print(resp.status_code)

            print("We couldn't connect to our server", resp.status_code)

    except requests.exceptions.ConnectionError:

        print("Connection Error! Http status Code {}".format(resp.status_code))

        sys.exit()

    except (requests.exceptions.RequestException,
            requests.exceptions.HTTPError):

        print("Ambiguous Error! Http status Code {}".format(resp.status_code))

        sys.exit()
def get_cube_mutual_funds_individual_intent_handler(request):
    resp = mutual_funds_api()

    try:

        if resp.status_code == 200:
            # extracting data in json format
            resp_dict = resp.json()

            mutual_fund_amount = resp_dict['details']['fund']['balance']
            # TODO make the mutual fund dynamic so I can call on the variable as a request
            # TODO have to match a mutualFund in the database

            mutualFund = request.get_slot_value['mutualFund']

            if mutualFund is not None:

                request.session['mutual_fund_individual'] = mutualFund

                speech_output = find_the_value('get_cube_mutual_funds_individual') + "with " + \
                                string.capwords(mutualFund) + ": " + mutual_fund_amount

                card = alexa.create_card(
                    title="Cube Intents",
                    subtitle="Cube Mutual Funds Individual",
                    content=speech_output)

                return alexa.create_response(
                    message=speech_output,
                    reprompt_message="I did not hear you",
                    end_session=False,
                    card_obj=card)

            else:

                speech_output = "You did not mention a mutual fund in the Cube database"

                card = alexa.create_card(
                    title="Cube Intents",
                    subtitle="Cube Mutual Funds Individual",
                    content=speech_output)

                return alexa.create_response(
                    message=speech_output,
                    reprompt_message="I did not hear you",
                    end_session=False,
                    card_obj=card)

        else:

            print(resp.status_code)

            print("We couldn't connect to our server", resp.status_code)

    except requests.exceptions.ConnectionError:

        print("Connection Error! Http status Code {}".format(resp.status_code))

        sys.exit()

    except (requests.exceptions.RequestException,
            requests.exceptions.HTTPError):

        print("Ambiguous Error! Http status Code {}".format(resp.status_code))

        sys.exit()