예제 #1
0
def login_otp(request):
    resp3 = get_cube_otp_intent_handler(request)

    try:

        if resp3.status_code == 200:
            # resp3(status=status.HTTP_200_OK):

            resp_dict = resp3.json()

            access_token = resp_dict['access_token']

            # TODO save acess_token credentials here
            speech_output = "Log-in Successful. You can ask me questions. Now, what can I help you with?"

            card = alexa.create_card(title="Welcome",
                                     subtitle=None,
                                     content=speech_output)

            return alexa.create_response(
                message=speech_output,
                reprompt_message=
                "For instructions on what you can say, please say help me!",
                end_session=False,
                card_obj=card)

        else:

            print(resp3.status_code)

            speech_output = "Connection Error! Http status Code {}".format(
                resp3.status_code)

            card = alexa.create_card(title="Failed",
                                     subtitle=None,
                                     content=speech_output)

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

    except requests.exceptions.ConnectionError:

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

        sys.exit()

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

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

        sys.exit()
예제 #2
0
def login_phone_number(request):
    resp2, response = get_cube_launch_intent_handler(request)

    try:

        if resp2.status_code == 200:
            # (status=status.HTTP_200_OK):

            speech_output = "What is the OTP?"

            card = alexa.create_card(title="Cube Launch",
                                     subtitle=None,
                                     content=speech_output)

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

        else:
            print(resp2.status_code)

            card = alexa.create_card(
                title="Cube Launch",
                subtitle="We couldn't connect to our server",
                content=None)

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

    except requests.exceptions.ConnectionError:

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

        sys.exit()

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

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

        sys.exit()
예제 #3
0
def get_cancel_intent_handler(request):
    speech_output = "Thank you for trying Cube. Have a nice day!"

    card = alexa.create_card(title="Cancel Cube",
                             subtitle=None,
                             content=speech_output)

    return alexa.create_response(message=speech_output,
                                 reprompt_message="{0}".format(speech_output),
                                 end_session=True,
                                 card_obj=card)
예제 #4
0
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()
예제 #5
0
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()
예제 #6
0
def on_processing_error(exc):
    '''
    :param exc exception instance
    '''

    speech_output = "Cube is having difficulty fulfilling your request."

    if exc:
        speech_output = "I am having difficulty fulfilling your request. {0}".format(
            exc.message)

    card = alexa.create_card(title="Cube Error",
                             subtitle=None,
                             content=speech_output)

    return alexa.create_response(message=speech_output,
                                 reprompt_message="I did not hear you",
                                 end_session=True,
                                 card_obj=card)
예제 #7
0
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()
예제 #8
0
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()
예제 #9
0
def get_cube_faq_intent_handler(request):
    x = request.get_slot_value['x']

    request.session['x'] = x

    if x is not None:

        if x == "Sell Investments":

            text = find_the_value_html('Sell Investments')

            speech_output = text

            card = alexa.create_card(
                title="FAQ Intent",
                subtitle="Sell Investments",
                content="Ever tried deciding what investments to sell and "
                "what to keep when you need cash?")

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

        elif x == "Cube ATM":

            text = find_the_value_html('Cube ATM')

            speech_output = text

            card = alexa.create_card(
                title="FAQ Intent",
                subtitle="Cube ATM",
                content="We all need funds in an emergency once in a while. "
                "That’s when we head to the nearest ATM.")

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

        elif x == "Rewards":

            text = find_the_value_html('Rewards')

            speech_output = text

            card = alexa.create_card(
                title="FAQ Intent",
                subtitle="Rewards",
                content=
                "We are all tired of the complex reward programs out there. "
                "Terms. Conditions. Expiry dates.")

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

        elif x == "Full Automation":

            text = find_the_value_html('Full Automation')

            speech_output = text

            card = alexa.create_card(
                title="FAQ Intent",
                subtitle="Full Automation",
                content="Congratulations on setting up your money life - "
                "you will see the fruits of your work from Sunday morning as "
                "we automate the last paise of your money to make your life better"
            )

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

        elif x == "Do Good":

            text = find_the_value_html('Do Good')

            speech_output = text

            card = alexa.create_card(
                title="FAQ Intent",
                subtitle="Do Good",
                content=
                "Ever wondered what you could do to help the less fortunate?")

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

        elif x == "Let's Get Rich":

            text = find_the_value_html("Let's Get Rich")

            speech_output = text

            card = alexa.create_card(
                title="FAQ Intent",
                subtitle="Let's Get Rich",
                content="Investing your money is hard. Where do you invest? "
                "What if you need it in an emergency?")

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

        elif x == "Lazy Money":

            text = find_the_value_html('Lazy Money')

            speech_output = text

            card = alexa.create_card(
                title="FAQ Intent",
                subtitle="Lazy Money",
                content=
                "Let's tackle the money that sits around in your bank account."
            )

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

    else:

        speech_output = "What do you need help with? You can mention topics such as Lazy Money, " \
                        "Let's Get Rich, Do Good, Full Automation, Rewards, Cube ATM, Sell Investments"

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

        return alexa.question(message=speech_output,
                              reprompt_message="I did not hear you",
                              end_session=False,
                              card_obj=card)
예제 #10
0
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()
예제 #11
0
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()
예제 #12
0
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()
예제 #13
0
def login_welcome(request):

    headers = {
        'Authorization': 'Basic Y3ViZWFwcGJhc2ljOmN1YmVhcHBiYXNpY0AyMDkwKQ==',
        'Content-type': 'application/x-www-form-urlencoded',
        'Content-Length': '60'
    }

    payload = {
        'identifier': 'user',
        'grant_type': 'client_credentials',
        'passcode': 'admin'
    }

    session = requests.Session()

    resp = session.post("https://api.bankoncube.com/v1/api/oauth/token",
                        headers=headers,
                        data=payload)

    try:

        if resp.status_code == 200:
            # (status=status.HTTP_201_CREATED):
            speech_output = "Welcome to Cube. To get you started, please tell me the phone number that you " \
                            "used to register with Cube. " \
                            "Say it in the following format: " + "<say-as interpret-as=\"digits\">" + "123 " + \
                            "</say-as>" + "<say-as interpret-as=\"digits\">" + "456" + "</say-as>" + \
                            "<say-as interpret-as=\"digits\">" + "7890" + "</say-as>"

            card = alexa.create_card(
                title="Cube Welcome Page",
                subtitle="Test card output",
                content=
                "Welcome to Cube. To get you started, please tell me the "
                "phone number that you used to register with Cube. Say it in the "
                "following format: 123 456 7890")

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

            return response1

        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()