예제 #1
0
def subscribe_to_bill_updates():

    r = twiml.Response()

    bill_id = read_context('bill_id')
    if not bill_id:
        r.redirect(url_for('.bills'))
        return r

    bill = data.get_bill_by_id(bill_id)
    if not bill:
        r.say("No bill was found matching %s" % bill_id)
        r.redirect(url_for('.bills'))
        return r

    if 'from' in g.call:

        params = {
            'phone': g.call['from'],
            'interest_type': 'item',
            'item_type': 'bill',
            'item_id': bill_id,
            'source': 'call_on_congress',
        }

        if data.subscribe_to_bill_updates(**params):
            r.say('You have been subscribed. A confirmation message has been sent to %s.' % " ".join(g.call['from'][1:]))
        else:
            r.say('Sorry, there was an error subscribing you.')

    else:
        r.say('Sorry, we were unable to identify your phone number.')

    r.redirect(url_for('.bills'))
    return str(r)
예제 #2
0
def bill():
    """Details about, and options for, a specific bill"""

    r = twiml.Response()
    bill = data.get_bill_by_id(g.request_params['bill_id'])
    if not bill:
        r.say("No bill was found matching")
        r.say("%s" % g.request_params['bill_id'])
        r.redirect(url_for('.bills'))
        return r

    write_context('bill_id', bill['bill_id'])

    if 'Digits' in g.request_params.keys():
        if g.request_params['Digits'] == '3':
            pass
        else:
            return handle_selection(r, menu='bill', selection=g.request_params['Digits'],
                                    params={'bill_id': bill['bill_id']})

    ctx = bill['bill_context']

    if len(bill.get('summary', '')) > 800 and not 'Digits' in g.request_params:
        with r.gather(numDigits=1, timeout=2) as rg:
            words = bill['summary'].split()
            rg.say("This bill's summary is")
            rg.say(" %d " % len(words))
            rg.say("words. Press 3 now to hear the long version, including the summary.")

    with r.gather(numDigits=1, timeout=1) as rg:
        rg.say("{bill_type} {bill_number}: {bill_title}".format(**ctx))
        if bill.get('summary') and g.request_params.get('Digits') == '3':
            rg.say(bill['summary'])
        if ctx.get('sponsor'):
            rg.say(ctx['sponsor'])
        cosponsors = ctx.get('cosponsors')
        if cosponsors:
            if len(bill.get('cosponsor_ids', [])) > 8:
                rg.say('This bill has %d cosponsors.' % len(bill['cosponsor_ids']))
            else:
                rg.say(ctx['cosponsors'])
        if ctx.get('bill_status'):
            rg.say(ctx['bill_status'])

    if 'next_url' in g.request_params.keys():
        r.redirect(g.request_params['next_url'])
        return r

    with r.gather(numDigits=1, timeout=settings.INPUT_TIMEOUT) as rg:
        rg.say("""Press 1 to get text message updates about this bill on your mobile phone.
                  Press 2 to search for another bill.""")
        rg.say("""To return to the previous menu, press 9""")
        rg.say("""Press 0 to return to the main menu.""")

    r.redirect(url_for('.bill'))
    return r