示例#1
0
def get_quote_type():
    dialog_state = get_dialog_state()
    session.attributes["STATE"] = 'GetQuoteType'
    session.attributes_encoder = json.JSONEncoder
    if dialog_state == 'STARTED':
        session.attributes['Category'] = 'positive'
        return delegate()
    elif dialog_state == 'IN_PROGRESS':
        session.attributes['Category'] = request['intent']['slots'][
            'Category']['value']
        return delegate()
    elif dialog_state == 'COMPLETED':
        session.attributes['Category'] = request['intent']['slots'][
            'Category']['value']
        return give_quote(category=session.attributes['Category'])
示例#2
0
def hotels():
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    city = request.intent.slots.city.resolutions.resolutionsPerAuthority[0][
        'values'][0]['value']['name']
    print(city)
    #print(user_id_alexa)
    city_alexa = city.lower()
    h = 'Hotels are: \n'
    i = 1
    con = sqlite3.connect("tripdb.db")
    cur = con.cursor()
    cur.execute("select * from hotel where city=?", (city_alexa, ))
    rows = cur.fetchall()
    if rows:
        for row in rows:
            #print(row)
            h = h + str(i) + ': ' + row[1] + ' ' + 'Rent=' + str(
                row[3]) + ',' + '\n'
            i = i + 1
        i = 1
        h = h + '.'
        return question(h + 'To book, go to www.makemytrip.com')
    else:
        return question('No hotels in this city')
示例#3
0
def cancelBooking(username, password, t_nn):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    t_type = request.intent.slots.t_type.resolutions.resolutionsPerAuthority[
        0]['values'][0]['value']['name']
    u_id_alexa = username.lower()
    pwd = password.lower()
    con = sqlite3.connect("tripdb.db")
    cur = con.cursor()
    cur.execute("select * from user where user_id=?", (u_id_alexa, ))
    rows = cur.fetchall()
    if rows:
        for row in rows:
            s = row[1]
        if s == pwd:
            cur.execute(
                "select * from booking_details where u_id=? and t_type=? and t_no=?",
                (u_id_alexa, t_type, t_nn))
            rows = cur.fetchall()
            if rows:
                for row in rows:
                    cur.execute(
                        "delete from booking_details where u_id=? and t_type=? and t_no=?",
                        (u_id_alexa, t_type, t_nn))
                    con.commit()
                return question("Your booking is cancelled successfully")
            else:
                return question("No such booking exists")
        else:
            return question("Password is wrong. Please Try again.")
    else:
        return question("Username does not exist. Create new account.")
示例#4
0
def organize_party(date, time, location):
    if date is None or time is None or location is None:
        return delegate()

    Event.create_event(location, date, time)
    return statement('Organizing a party on ' + date + ' at ' + time + ' at ' +
                     location)
示例#5
0
def book_appointment(device_serial_number, phone_number, appointment_date,
                     appointment_time, problem_statement, zip_code):
    # delegate dialog to Alexa until all parameters are set
    dialog_state = get_dialog_state()
    print(dialog_state)
    if dialog_state != "COMPLETED":
        return delegate(None)
    print(device_serial_number, phone_number, appointment_date,
          appointment_time, problem_statement, zip_code)
    #Send SMS with acknowledgement number
    client = Client(os.environ.get('TWILIO_ACCOUNT_SID'),
                    os.environ.get('TWILIO_AUTH_TOKEN'))
    client.messages.create(
        from_='+14696467609',
        to='+15108949478',
        body='Your request for appointment on the ' + appointment_date +
        ' at ' + appointment_time +
        '. been successfully submitted. The service request number is 456756435.'
    )
    #speak out response
    return statement(
        '<speak> Your request for an appointment on the ' + appointment_date +
        ' at ' + appointment_time +
        '. has been successfully submitted. The service request number is <say-as interpret-as="digits">456756435</say-as> <break time="1s"/> We have sent you an SMS with the details to your mobile number.</speak>'
    )
示例#6
0
def systemstatchange(status_sys):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    speech_text = None
    if os.name=="posix":
        if status_sys.lower() == "shutdown":
            os.system("shutdown -h +1")
            speech_text = "Shutdown in 1 Min. \nGhost Busted. See You Next Time"
            return statement(speech_text)
        elif status_sys.lower() == "restart":
            os.system("reboot")
            speech_text = "Restart in 1 Min. \nGhost Busted. See You Next Time"
            return statement(speech_text)
        elif status_sys.lower() == "lock":
            os.system("gnome-screensaver-command --lock")
            speech_text = "Screen Locked."
    elif os.name=="nt":
        if status_sys.lower() == "shutdown":
            os.system("shutdown /s /t 1")
            speech_text = "Shutdown in 1 Min. \nGhost Busted. See You Next Time"
            return statement(speech_text)
        elif status_sys.lower() == "restart":
            os.system("shutdown /r /t 1")
            speech_text = "Restart in 1 Min. \nGhost Busted. See You Next Time"
            return statement(speech_text)
        elif status_sys.lower() == "lock":
            ctypes.windll.user32.LockWorkStation()
            speech_text = "Screen Locked."
    else:
        speech_text = "Unable to process request"
    return question(speech_text)
def fetchPrice(currency):
    if (currency != None):
        # print("session: ")
        # print(ask_session)
        currency = currencyCode(currency)
        URL = "http://alexaskill.pythonanywhere.com/?action=price&crypto=" + currency
        #    print('given currency is:',currency)
        r = requests.get(URL)
        data = r.json()
        change = data['change']
        curPrice = data['price']
        percent = abs(change / data['price_old'])
        delta = ""
        if (change > 0):
            delta = "an increase of {:.3f} percent from last 24 hours".format(
                percent)
        elif (change < 0):
            delta = "an increase of {:.3f} percent from last 24 hours".format(
                percent)
        else:
            delta = "same as yesterday"
        msg = str(curPrice) + " US dollars" + " which is " + str(delta)
        return question(msg).simple_card(title="Current Price", content=msg)
    else:
        if (ask_session['dialogState'] != "COMPLETED"):
            return delegate()
示例#8
0
def set_dinner_single(dinner=None):
    log.debug('Entering Set Dinner Single')
    if convert_errors:
        return question('I had trouble understanding you. Can you ask again?')
    confirm_status = get_confirmation_status()
    if confirm_status == 'DENIED':
        return statement('Okay.')
    log.debug('Set Dinner Single Confirmation Status is: ' + confirm_status)
    if dinner:
        log.debug('Set Dinner Single Dinner Specified')
        if check_dinner(date=dt.today()) and confirm_status != 'CONFIRMED':
            log.debug('Set Dinner Single Dinner Exists for Today')
            # Dinner set for today
            speech_text = """You already have {} set for tonight.
            Would you like to change it to {}?""".format(
                get_dinner_date(dt.today()).name,
                dinner)
            return confirm_intent(speech_text)
        else:
            log.debug('Set Dinner Single Setting Dinner to: ' + dinner)
            set_dinner(name=dinner, date=dt.today())
            return statement('Dinner has been set! Don\'t forget to rate the dinner after!')
    else:
        log.debug('Set Dinner Single Delegate')
        return delegate()
示例#9
0
def submitReading(MeterReading):
    if session.user.accessToken == None:
        return statement('To start using this skill, please use the companion app to authenticate on Amazon') \
         .link_account_card()
    else:
        # delegate dialog to Alexa until all parameters are set
        dialog_state = get_dialog_state()
        print(dialog_state)
        if dialog_state != "COMPLETED":
            return delegate(None)
        # get account reference from access token
        accesstoken = session.user.accessToken
        accountreference = getaccountreference(accesstoken)
        meterreading = MeterReading
        print(accesstoken, accountreference, meterreading)
        # Send SMS with meter reading
        client = Client(os.environ.get('TWILIO_ACCOUNT_SID'),
                        os.environ.get('TWILIO_AUTH_TOKEN'))
        client.messages.create(
            body='Your meter reading ' + meterreading +
            '. is successfully submitted for your account reference number ' +
            accountreference + '. Thank you',
            from_='whatsapp:+14155238886',
            to='whatsapp:+919840610434')
        #speak out response
        return statement(
            '<speak> Your meter reading <say-as interpret-as="digits">' +
            meterreading +
            '</say-as> is successfully submitted for your account reference number <say-as interpret-as="digits">'
            + accountreference +
            '</say-as>. Thank you. We have sent you an SMS with the details to your mobile number. </speak>'
        )
示例#10
0
def Faqtopic(faqtopic):
    #delegate dialog to Alexa until all parameters are set
    dialog_state = get_dialog_state()
    print(dialog_state)
    if dialog_state != "COMPLETED":
        return delegate(speech=None)
    slotvalue = faqtopic
    print(slotvalue)
    list_1 = [
        'top up my phone', 'topup my phone', 'topup', 'top up', 'recharge',
        'recharge my phone', 'top of my phone', 'top pop my phone',
        'recharge my phone', 'recharge my balance'
    ]
    list_2 = ['no signal', 'signal issues', 'low signal']
    list_3 = [
        'setup my phone for the internet', 'set up my phone for the internet',
        'setup my phone to the internet', 'set up my phone for the internet'
    ]
    if slotvalue in list_1:
        return statement(
            'There are various options for recharging your Prepaid Mobile or Mobile Broadband service. The My Optus app is the easiest way to top up or recharge. You can also store your credit card details to make your next recharge even easier. The My Optus app is available on Android and Apple smartphones. Recharge over the phone with a credit card by calling 555 from your Prepaid Mobile. Dont worry if you have run out of credit as calls to 555 are free. AutoRecharge is the simplest way to stay on top of your Prepaid plan. Just choose up the amount you want to recharge and the frequency of how often you would like the recharge to be applied. We will take care of the rest.'
        )
    elif slotvalue in list_2:
        return statement(
            'To check for a problem with the Optus Mobile Network & service in your area, see our coverage maps at www.optus.com.au/about/network/service-status.  Once you have selected the Outage tab and entered an address or location at the top of the map,  you will be presented with all the towers in the searched area. Red coloured tower or towers indicate there is a problem or outage, Orange coloured tower indicate we are performing maintenance or upgrades and Green coloured tower indicate that everything is running okay.'
        )
    elif slotvalue in list_3:
        return statement(
            'To set up, configure or troubleshoot your new device, check out our animated guides. They are all located at www.devicehelp.optus.com.au for selected devices and are are simple to follow online.'
        )
    else:
        return statement(
            'Kindly try our FAQ page at www.optus.com.au for answers to your queries'
        )
示例#11
0
def play_music(file_type, file_name):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    if os.name == 'posix':
        dir_path = os.path.dirname(os.environ['HOME'])
        if file_type == 'song' or file_type == 'music':
            for root, dirs, files in os.walk(dir_path):
                for file in files:
                    if file.endswith('.mp3'):
                        d = fuzz.token_set_ratio(file, file_name)
                        if d >= 80:
                            matches = (root + '/' + str(file))
                            speech_text = 'Playing %s on System' % file_name
                            webbrowser.open(matches)
                            return question(speech_text)
                        else:
                            speech_text = 'Unable to find file %s' % file_name
        if file_type == 'video' or file_type == 'movie':
            for root, dirs, files in os.walk(dir_path):
                for file in files:
                    if file.endswith('.mp4'):
                        d = fuzz.token_set_ratio(file, file_name)
                        if d >= 80:
                            matches = (root + '/' + str(file))
                            speech_text = 'Playing %s on System' % file_name
                            webbrowser.open(matches)
                            return question(speech_text)
                        else:
                            speech_text = 'Unable to find file %s' % file_name
    elif os.name == 'nt':
        path = get_path()
        if file_type == 'song' or file_type == 'music':
            for drive in path:
                for root, dirs, files in os.walk(drive):
                    for file in files:
                        if file.endswith('.mp3'):
                            d = fuzz.token_set_ratio(file, file_name)
                            if d >= 80:
                                matches = (root + '/' + str(file))
                                speech_text = 'Playing on System'
                                webbrowser.open(matches)
                                return question(speech_text)
                            else:
                                speech_text = 'Unable to find file'
                return question(speech_text)
        if file_type == 'video' or file_type == 'movie':
            for drive in path:
                for root, dirs, files in os.walk(drive):
                    for file in files:
                        if file.endswith('.mp4'):
                            d = fuzz.token_set_ratio(file, file_name)
                            if d >= 80:
                                matches = (root + '/' + str(file))
                                speech_text = 'Playing on System'
                                webbrowser.open(matches)
                                return question(speech_text)
                            else:
                                speech_text = 'Unable to find file'
    return question(speech_text)
示例#12
0
def callbackrequest(Scheduledate):
    if session.user.accessToken == None:
        return statement('To start using this skill, please use the companion app to authenticate on Amazon') \
         .link_account_card()
    else:
        #delegate dialog to Alexa until all parameters are set
        dialog_state = get_dialog_state()
        print(dialog_state)
        if dialog_state != "COMPLETED":
            return delegate(None)
        # get account reference from access token
        Callbackdate = Scheduledate
        accesstoken = session.user.accessToken
        accountreference = getaccountreference(accesstoken)
        print(accesstoken, accountreference)
        client = Client(os.environ.get('TWILIO_ACCOUNT_SID'),
                        os.environ.get('TWILIO_AUTH_TOKEN'))
        client.messages.create(
            from_='+14696467609',
            to='+917338856833',
            body=
            'Your callback has been scheduled between 10 AM and 11 AM on the '
            + Callbackdate + '. Thank you.')
        return statement(
            '<speak> Your callback has been scheduled between 10 A M and 11 A M on <say-as interpret-as="date"> '
            + Callbackdate + '</say-as>. Thank you </speak>')
示例#13
0
def play_music(file_type, file_name):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    if file_type == 'song' or file_type == 'music':
        dir_path = os.path.dirname(homedir)
        for root, dirs, files in os.walk(dir_path):
            for file in files:
                if file.endswith('.mp3'):
                    d = fuzz.token_set_ratio(file, file_name)
                    if d >= 80:
                        matches = (root + '/' + str(file))
                        speech_text = 'Playing %s on System' % file_name
                        webbrowser.open(matches)
                        return question(speech_text)
                    else:
                        speech_text = 'Unable to find file %s' % file_name
        return question(speech_text)
    if file_type == 'video' or file_type == 'movie':
        dir_path = os.path.dirname(homedir)
        for root, dirs, files in os.walk(dir_path):
            for file in files:
                file1 = file.replace(' ', '')
                if file1.endswith('.mp4'):
                    d = fuzz.token_set_ratio(file1, file_name)
                    if d >= 80:
                        matches = (root + '/' + str(file))
                        speech_text = 'Playing %s on System' % file_name
                        webbrowser.open(matches)
                        return question(speech_text)
                    else:
                        speech_text = 'Unable to find file %s' % file_name
        return question(speech_text)
示例#14
0
def accessfile(file_name):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    os.system('gedit "{0}"'.format(file_name))
    speech_text = 'File open in Editor %s' % file_name
    return question(speech_text)
示例#15
0
def alexa_order_drink(person, drink):
  if ask_session['dialogState'] != 'COMPLETED' or drink is None or person is None:
    return delegate()

  person = resolve_synonym('person', person)  
  username = find_person(person)
  if username is None:
    return statement("Sorry I don't know {}".format(person))

  drink = resolve_synonym('drink', drink)
  drink_id = find_drink(drink)
  if drink_id is None:
    return statement("Sorry, I could not find a drink called {}".format(drink))

  quantity_remaining = _quantities.get(drink_id, 0)

  if quantity_remaining < 1:
    return statement("Sorry, but we have run out of {}".format(drink))

  _place_order_impl(username, drink_id)
    
  return statement(random.choice([
                                 "I've notified the butler",
                                 "Okay",
                                 "Your drink is on its way",
                                 "I'll let him know",
                                 ]))
def addition(first, second):
    dialog_state = get_dialog_state()
    if dialog_state != "COMPLETED":
        return delegate()

    sum = first + second
    return statement('The sum of {} and {} is {}'.format(first, second, sum))
示例#17
0
def one_shot_departure(direction, mode):
    log.info("OneShotDepartureIntent got direction={}, mode={}".format(
        direction, mode))
    if not dialog_completed():
        return delegate()

    departures = _make_trafiklab_request(origin=db.get_default_site(
        session.user.userId),
                                         direction=direction,
                                         mode=mode)

    if not departures:  # empty list returned
        return statement(render_template('sl_error', mode=mode))

    departures_first = []
    departures_next = []

    for departure in departures:
        if departure.destination not in [
                departure.destination for departure in departures_first
        ]:
            departures_first.append(departure)
        else:
            departures_next.append(departure)

    # store next set of departures in session variables
    session.attributes['mode'] = mode
    session.attributes['next_departures'] = departures_next

    first_departures_statement = render_departure_response(mode,
                                                           departures_first,
                                                           follow_up=True)
    log.info('Returning {}'.format(first_departures_statement))
    return question(first_departures_statement)
示例#18
0
def accessfile(file_name):
	dialog_state = get_dialog_state()
	if dialog_state != 'COMPLETED':
		return delegate()
	subprocess.call(['notepad.exe', 'file_name'])
	speech_text = 'file open %s'%file_name
	return question(speech_text)
示例#19
0
def execute_file(file_name):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    speech_text = None
    if os.name == "posix":
        path = '/usr/bin'
        for file in os.listdir(path):
            d = fuzz.token_set_ratio(file, file_name)
            if d >= 95:
                match = (path+ '/' + str(file))
                subprocess.Popen(match)
                speech_text = '%s running on Device'%file_name
    elif os.name == "nt":
        path = 'C://'
        for root, dirs, files in os.walk(path):
            for file in files:
                if file.endswith('.exe'):
                    d = fuzz.token_set_ratio(file, file_name)
                    if d == 100:
                        matches = (root + '/' + str(file))
                        subprocess.Popen(matches)
                        speech_text = '%s running on Device'%file_name
    if speech_text == None :
        speech_text = "Unable to find requested program."
    return question(speech_text)
示例#20
0
def division(first, second):
    dialog_state = get_dialog_state()
    if dialog_state != "COMPLETED":
        return delegate()

    division = first / second
    return statement('The division of {} and {} is {}'.format(
        first, second, division))
def subtraction(first, second):
    dialog_state = get_dialog_state()
    if dialog_state != "COMPLETED":
        return delegate()

    difference = first - second
    return statement('The difference between {} and {} is {}'.format(
        first, second, difference))
def multiplication(first, second):
    dialog_state = get_dialog_state()
    if dialog_state != "COMPLETED":
        return delegate()

    product = first * second
    return statement('The product of {} and {} is {}'.format(
        first, second, product))
示例#23
0
def preference_dialog(firstPreference, secondPreference):
    dialog_state = get_dialog_state()
    if dialog_state == "STARTED":
        return delegate()
    return statement(
        "Okay, lasst mich euer Problem lösen. Ich bin ein super Streitschlichter."
        "Glücklicherweise habe ich gerade in meinem Knowledge Graph einen Film gefunden der eure beiden"
        "Vorlieben {} und {} zufriedenstellt. Der Film heißt Top Gun!".format(
            firstPreference, secondPreference))
示例#24
0
def play_music(file_type,file_name):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()
    speech_text = None
    if os.name == 'posix':
        dir_path = os.path.dirname(os.environ['HOME'])
        if file_type == 'song' or file_type == 'music':
            for root, dirs, files in os.walk(dir_path):
                for file in files:
                    if file.endswith('.mp3'):
                        d = fuzz.token_set_ratio(file, file_name)
                        if d >= 95:
                            matches=(root + '/'+str(file))
                            speech_text = 'Playing %s %s on System'%(file_type,file_name)
                            webbrowser.open(matches)
        if file_type == 'video' or file_type == 'movie':
            for root, dirs, files in os.walk(dir_path):
                for file in files:
                    if file.endswith('.mp4'):
                        d = fuzz.token_set_ratio(file, file_name)
                        if d>=98:
                            matches=(root + '/'+str(file))
                            speech_text = 'Playing %s %s on System'%(file_type,file_name)
                            webbrowser.open(matches)
        if speech_text == None:
            speech_text = 'Unable to find %s'%file_name
    elif os.name == 'nt':
        speech_text = None
        path = get_path()
        path.remove('C:\\')
        if file_type == 'song' or file_type == 'music':
            for drive in path:
                for root, dirs, files in os.walk(drive):
                    for file in files:
                        file1 = file.replace('', '')
                        if file1.endswith('.mp3'):
                            d = fuzz.token_set_ratio(file1, file_name)
                            if d >= 98:
                                matches = (root + '/'+str(file))
                                speech_text = 'Playing %s %s on System'%(file_type,file_name)
                                webbrowser.open(matches)
        if file_type == 'video' or file_type == 'movie':
            for drive in path:
                for root, dirs, files in os.walk(drive):
                    for file in files:
                        file1 = file.replace('', '')
                        if file1.endswith('.mp4'):
                            d = fuzz.token_set_ratio(file1, file_name)
                            if d >= 98:
                                matches = (root + '/'+str(file))
                                webbrowser.open(matches)
                                speech_text = 'Playing %s %s on System'%(file_type,file_name)
        if speech_text == None:
            speech_text = 'Unable to find %s'%file_name
    return question(speech_text)
def modulus(first, second):
    dialog_state = get_dialog_state()
    if dialog_state != "COMPLETED":
        return delegate()

    if second == 0:
        return statement('Sorry I cannot divide by zero it doesnt make sense.')
    remainder = first % second
    return statement('The mod of {} and {} is {}'.format(
        first, second, remainder))
def division(first, second):
    dialog_state = get_dialog_state()
    if dialog_state != "COMPLETED":
        return delegate()

    if second == 0:
        return statement('Sorry I cannot divide by zero it doesnt make sense.')
    quotient = first // second
    return statement('The quotient of {} and {} is {}'.format(
        first, second, quotient))
def share_headlines(news_type):
    dialog_state = get_dialog_state()
    if dialog_state != 'COMPLETED':
        return delegate()

    if news_type is not "None":
        headlines = get_headlines(news_type)
        headline_msg = 'The current news headlines are {}'.format(headlines)
        return statement(headline_msg)
    else:
        no_intent()
示例#28
0
def accountBalance(AccountReference):
    # delegate dialog to Alexa until all parameters are set
    dialog_state = get_dialog_state()
    print(dialog_state)
    if dialog_state != "COMPLETED":
        return delegate(speech=None)
    CustAcc = AccountReference
    print(CustAcc)
    speech = '<speak> Your account balance is <say-as interpret-as="cardinal">450</say-as> pounds. Thank you </speak>'
    print(speech)
    return statement(speech).simple_card('Account Balance', speech)
示例#29
0
def paymentduedate(AccountReference):
    # delegate dialog to Alexa until all parameters are set
    dialog_state = get_dialog_state()
    print(dialog_state)
    if dialog_state != "COMPLETED":
        return delegate(speech=None)
    CustAcc = AccountReference
    print(CustAcc)
    speech = '<speak> Your payment due date is <say-as interpret-as="date">20180528</say-as> </speak>'
    print(speech)
    return statement(speech).simple_card('Payment Due Date', speech)
示例#30
0
def paymentduedate(AccountReference):
    # delegate dialog to Alexa until all parameters are set
    dialog_state = get_dialog_state()
    print(dialog_state)
    if dialog_state != "COMPLETED":
        return delegate(speech=None)
    CustAcc = AccountReference
    print(CustAcc)
    speech = '<speak> Your request for water meter has been successfully placed. We will contact you within 7 days </speak>'
    print(speech)
    return statement(speech).simple_card('Water Meter request', speech)