def index(request):

	r = Result(request.body)        
        print "request.body : %s" % request.body

	t = Tropo()

	answer = r.getInterpretation()
	value = r.getValue()
        
	t.say("You said " + answer + ", which is a " + value)
        
        actions_options_array = ['name', 'attempts', 'disposition', 'confidence', 'interpretation', 'utterance', 'value', 'concept', 'xml', 'uploadStatus']
        actions = r.getActions()
	if (type (actions) is list):
	     for item in actions:
		for opt in actions_options_array:
                    print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {'actionfieldname':opt, "vaalue":item.get(opt,'NoValue')}
                print '------------------------------'
             
       	else:
            dict = actions
	    for opt in actions_options_array:
                print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {'actionfieldname':opt, "vaalue":dict.get(opt,'NoValue')}
        
        json = t.RenderJson()
        print json
	return json
Beispiel #2
0
def talkto(request):
    r = Result(request.body)
    t = Tropo()

    answer = r.getInterpretation()

    if answer == "goodbye":
        t.say("Thank you for calling, have a good day")

        return t.RenderJson()

    t.say("As we currently do not have transfer abilites, here is the phone number: ")

    db = MySQLdb.connect(host="localhost", user="******", passwd="globalhack", db="globalhackv")
    cur = db.cursor()

    cur.execute(
        "SELECT `Court Clerk Phone Number` as `phone` from `munipality` where `Municipality` = UPPER(%s)", (answer,)
    )
    result = cur.fetchone()

    cur.close()
    db.close()

    if result[0] == "":
        t.say("We are sorry, we do not have a phone number for this court.")

        return t.RenderJson()

    t.say(result[0])

    return t.RenderJson()
Beispiel #3
0
def license(request):
    r = Result(request.body)
    t = Tropo()

    answer = r.getInterpretation()

    u = current[r._sessionId]
    current[r._sessionId]["last_name"] = answer

    db = MySQLdb.connect(host="localhost", user="******", passwd="globalhack", db="globalhackv")
    cur = db.cursor()

    cur.execute(
        "SELECT first_name, last_name FROM good_data_fixed WHERE date_of_birth = %s AND last_name LIKE %s AND status <> 'CLOSED' AND status <> 'DISMISS WITHOUT COSTS'",
        (u["birthday"], answer),
    )
    result = cur.fetchall()

    cur.close()
    db.close()

    t.say("Hello %s %s," % (result[0][0], result[0][1]))

    choices = Choices("[4 DIGITS]", mode="dtmf", attempts=3)
    t.ask(
        choices,
        timeout=15,
        name="last_drivers",
        say="As a final validation, please enter the last four digits of your driver's license I D",
    )

    t.on(event="continue", next="/results")

    return t.RenderJson()
Beispiel #4
0
def deal_with_links():
    print "dealing with link"
    t = Tropo()
    # Load up everything the stupid way.
    userid = int(request.args['userid'])
    page_n = int(request.args['page'])
    user = User.query.filter_by(userid=userid).first()
    url = im_feeling_lucky(user.voice_query)
    webpage = extract.ParsedWebpage(url)

    # Get the action from last time.
    result = Result(request.data)
    try:
        result.getValue()
    except KeyError:
        t.say("Going to next page.")
        t.on(event='continue', next='/speak_webpage?userid={0}&page={1}'
            .format(userid, page_n + 1))
        return t.RenderJson()

    if result.getValue() == 'link':
        link_num = int(result.getInterpretation())
        print "Link number: ", link_num
        if link_num >= len(webpage.links):
            t.say("Invalid link")
            t.on(event='continue', next='/speak_webpage?userid={0}&page={1}'
                .format(userid, page_n))
            return t.RenderJson()
        t.say("Following link.")
        print "New url: ", webpage.links[link_num][1]
        user.voice_query = webpage.links[link_num][1]
        db.session.commit()
        t.on(event='continue', next='/speak_webpage?userid={0}&page={1}'
            .format(userid, 0))

    elif result.getInterpretation() == 'next':
        t.say("Going to next page.")
        t.on(event='continue', next='/speak_webpage?userid={0}&page={1}'
            .format(userid, page_n + 1))
    elif result.getInterpretation() == 'home':
        t.say("Going home.")
        t.on(event='continue', next='/home')
    else:
        t.say("Unknown command")
        t.on(event='continue', next='/speak_webpage?userid={0}&page={1}'
            .format(userid, page_n))
    return t.RenderJson()
Beispiel #5
0
def language_select():
    r = Result(request.data)
    s = CallSession(r)

    answer = r.getInterpretation()

    s.set('language', answer)

    return redirect(url_for('phone.hello'))
Beispiel #6
0
def birthday_day(request):
    r = Result(request.body)
    t = Tropo()

    answer = r.getInterpretation()

    current[r._sessionId]["birthday"]["month"] = answer

    choices = Choices("[1-2 DIGITS]", mode="dtmf")
    t.ask(choices, timeout=15, name="birthday_day", say="Please enter your date of birth", attempts=3)

    t.on(event="continue", next="/name")

    return t.RenderJson()
def index(request):

    r = Result(request.body)
    print "request.body : %s" % request.body

    t = Tropo()

    answer = r.getInterpretation()
    value = r.getValue()

    answer1 = r.getNamedActionInterpretation("directory")
    value1 = r.getNamedActionValue("directory")
    t.say("You said " + answer1 + ", which is a " + value1)

    answer2 = r.getNamedActionInterpretation("color")
    value2 = r.getNamedActionValue("color")
    t.say("You also said " + answer2 + ", which is a " + value2)

    count = r.getActionsCount()
    t.say("actions count is  " + str(count))
    for i in range(count):
        answer = r.getIndexdedInterpretation(i)
        value = r.getIndexedValue(i)
        t.say("You said " + answer + ", which is a " + value)

    actions_options_array = [
        'name', 'attempts', 'disposition', 'confidence', 'interpretation',
        'utterance', 'value', 'concept', 'xml', 'uploadStatus'
    ]
    actions = r.getActions()
    if (type(actions) is list):
        for item in actions:
            for opt in actions_options_array:
                print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {
                    'actionfieldname': opt,
                    "vaalue": item.get(opt, 'NoValue')
                }
            print '------------------------------'

    else:
        dict = actions
        for opt in actions_options_array:
            print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {
                'actionfieldname': opt,
                "vaalue": dict.get(opt, 'NoValue')
            }

    json = t.RenderJson()
    print json
    return json
Beispiel #8
0
def index(request):

	r = Result(request.body)        
        print "Result : %s" % r

	t = Tropo()

	answer = r.getInterpretation()
	value = r.getValue()

	t.say("You said " + answer + ", which is a " + value)

        json = t.RenderJson()
        print json
	return json
Beispiel #9
0
def index(request):

    r = Result(request.body)
    print "Result : %s" % r
    #        dump(r)
    t = Tropo()

    answer = r.getInterpretation()

    t.say("You said ")
    t.say(answer, _as="DIGITS")

    json = t.RenderJson()
    print json
    return json
def index(request):

	r = Result(request.body)        
        print "Result : %s" % r
#        dump(r)
	t = Tropo()

	answer = r.getInterpretation()

	t.say("You said ")
	t.say (answer, _as="DIGITS")

        json = t.RenderJson()
        print json
	return json
def index(request):

	r = Result(request.body)        
        print("Result : %s" % r)

	t = Tropo()

	answer = r.getInterpretation()
	value = r.getValue()

	t.say("You said " + answer + ", which is a " + value)

        json = t.RenderJson()
        print(json)
	return json
Beispiel #12
0
def birthday_month(request):
    r = Result(request.body)
    print r._sessionId
    t = Tropo()

    answer = r.getInterpretation()

    current[r._sessionId] = {"birthday": {"year": answer}}

    choices = Choices("[1-2 DIGITS]", mode="dtmf")
    t.ask(choices, timeout=15, name="birthday_month", say="Please enter your month of birth as a number", attempts=3)

    t.on(event="continue", next="/birthday_day")

    return t.RenderJson()
Beispiel #13
0
def name(request):
    r = Result(request.body)
    t = Tropo()

    answer = r.getInterpretation()

    current[r._sessionId]["birthday"]["day"] = answer

    b = current[r._sessionId]["birthday"]

    if len(b["month"]) == 1:
        b["month"] = "0" + b["month"]
    if len(b["day"]) == 1:
        b["day"] = "0" + b["day"]

    formatted_birthday = "%s-%s-%s" % (b["year"], b["month"], b["day"])
    current[r._sessionId]["birthday"] = formatted_birthday

    db = MySQLdb.connect(host="localhost", user="******", passwd="globalhack", db="globalhackv")
    cur = db.cursor()

    cur.execute("SELECT COUNT(*) AS count FROM good_data_fixed WHERE date_of_birth = %s", (formatted_birthday,))
    result = cur.fetchone()

    cur.execute("SELECT last_name FROM good_data_fixed WHERE date_of_birth = %s", (formatted_birthday,))
    people = cur.fetchall()

    cur.close()
    db.close()

    if int(result[0]) == 0:
        t.say("We have found zero results, have a good day!")
        return t.RenderJson()

    choices = []
    for row in people:
        print row[0]
        choices.append(row[0])
    names = ",".join(choices)

    t.ask(choices=names, say="Please say your last name", attempts=3)

    t.on(event="continue", next="/license")

    return t.RenderJson()
Beispiel #14
0
def country_select():
    r = Result(request.data)
    s = CallSession(r)

    answer = r.getInterpretation()

    s.set('country', answer)

    s_language = s.get('language')
    if not s_language:
        countries = data.get_countries()
        for s_country in countries:
            if s_country['name'].lower() == answer.lower():
                s.set('language', s_country['languages'][0]['name'])

    t = Tropo()
    t.on(event='continue', next=url_for('phone.hello'))

    return t.RenderJson()
def index(request):

    r = Result(request.body)        
    print "request.body : %s" % request.body

    t = Tropo()

    answer = r.getInterpretation()
    value = r.getValue()
    
    answer1 = r.getNamedActionInterpretation("directory")
    value1 = r.getNamedActionValue("directory")
    t.say("You said " + answer1 + ", which is a " + value1)
    
    answer2 = r.getNamedActionInterpretation("color")
    value2 = r.getNamedActionValue("color")
    t.say("You also said " + answer2 + ", which is a " + value2)
    
    
    count= r.getActionsCount()
    t.say("actions count is  " + str(count))
    for i in range(count):
        answer = r.getIndexdedInterpretation(i)
        value = r.getIndexedValue(i)    
        t.say("You said " + answer + ", which is a " + value)
        
    actions_options_array = ['name', 'attempts', 'disposition', 'confidence', 'interpretation', 'utterance', 'value', 'concept', 'xml', 'uploadStatus']
    actions = r.getActions()
    if (type (actions) is list):
        for item in actions:
            for opt in actions_options_array:
                    print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {'actionfieldname':opt, "vaalue":item.get(opt,'NoValue')}
            print '------------------------------'
             
    else:
        dict = actions
        for opt in actions_options_array:
                print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {'actionfieldname':opt, "vaalue":dict.get(opt,'NoValue')}
        
    json = t.RenderJson()
    print json
    return json
Beispiel #16
0
def country():
    r = Result(request.data)
    s = CallSession(r)

    answer = r.getInterpretation()

    countries = data.country_for_code(answer)

    t = Tropo()

    if not countries:
        t.ask(
            choices='[1-3 DIGITS]',
            name='code',
            say=_('Invalid country code, please try again.'),
            timeout=5,
        )
        t.on(event='continue', next=url_for('phone.country'))
    elif len(countries) == 1:
        t.say(_('You selected'))
        t.say(countries[0]['name'])
        s.set('country', countries[0]['name'])

        t.on(event='continue', next=url_for('phone.hello'))
    else:
        country_list = ', '.join(
            list(map(lambda country: country['name'], countries)))

        t.ask(
            choices=country_list,
            name='country',
            say=_('Please select one of the following countries. %s') %
            country_list,
            timeout=5,
        )
        t.on(event='continue', next=url_for('phone.country_select'))

    return t.RenderJson()
Beispiel #17
0
def index(request):

    r = Result(request.body)
    print "request.body : %s" % request.body

    t = Tropo()

    answer = r.getInterpretation()
    value = r.getValue()

    t.say("You said " + answer + ", which is a " + value)

    actions_options_array = [
        'name', 'attempts', 'disposition', 'confidence', 'interpretation',
        'utterance', 'value', 'concept', 'xml', 'uploadStatus'
    ]
    actions = r.getActions()
    if (type(actions) is list):
        for item in actions:
            for opt in actions_options_array:
                print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {
                    'actionfieldname': opt,
                    "vaalue": item.get(opt, 'NoValue')
                }
            print '------------------------------'

    else:
        dict = actions
        for opt in actions_options_array:
            print 'action object filed %(actionfieldname)s\'s value is %(vaalue)s' % {
                'actionfieldname': opt,
                "vaalue": dict.get(opt, 'NoValue')
            }

    json = t.RenderJson()
    print json
    return json
Beispiel #18
0
def results(request):
    r = Result(request.body)
    t = Tropo()

    answer = r.getInterpretation()

    u = current[r._sessionId]

    db = MySQLdb.connect(host="localhost", user="******", passwd="globalhack", db="globalhackv")
    cur = db.cursor()

    cur.execute(
        "SELECT court_date, court_location, violation_description, first_name, last_name, warrant_status, fine_amount, court_cost FROM good_data_fixed WHERE date_of_birth = %s AND last_name LIKE %s AND drivers_license_number LIKE %s AND status <> 'CLOSED' AND status <> 'DISMISS WITHOUT COSTS'",
        (u["birthday"], u["last_name"], "%" + answer),
    )
    result = cur.fetchall()

    cur.close()
    db.close()

    total_cost = 0
    total_fees = 0
    courts = []

    dates = {}
    for row in result:
        if row[0] not in dates:
            d = datetime.strptime(row[0], "%Y-%m-%d")
            nice = d.strftime("%A, %B, %-d, %Y")

            dates[row[0]] = {"date": nice, "location": row[1], "events": []}

        if not row[1] in courts:
            courts.append(row[1])

        dates[row[0]]["events"].append({"fine": row[6], "fee": row[7], "description": row[2], "warrant": row[5]})

        total_cost += float(row[6][1:])
        total_fees += float(row[7][1:])

    for date, info in dates.iteritems():
        t.say("You have a court date on %s. This is for the following violations" % (info["date"]))

        for violation in info["events"]:
            t.say("Violation " + violation["description"])

            if violation["fine"] != "":
                t.say("This includes a %s fine and %s court fee" % (violation["fine"], violation["fee"]))
                extra = "also"

            if violation["warrant"] == "TRUE":
                t.say("This %s includes a warrant for your arrest" % (extra))

    if total_cost > 0:
        t.say(
            "Your total fines are $%.2f and your total fees are $%.2f, bringing the total cost to $%.2f."
            % (total_cost, total_fees, total_cost + total_fees)
        )

    say = (
        "If you would like to talk to a court clerk about this, please say any of the following courts, or say goodbye: %s"
        % (", ".join(courts))
    )

    courts.append("goodbye")

    choice = Choices(",".join(courts))

    t.ask(choices=choice, say=say, attempts=3)
    t.on(event="continue", next="/talkto")

    return t.RenderJson()