def load_member_for(bioguide): for legislator in read_context('legislators', []): if legislator['bioguide_id'] == bioguide: write_context('legislator', legislator) return legislator legislator = data.legislator_by_bioguide(bioguide) write_context('legislator', legislator) return legislator
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
def zipcode_selection(): """Ensures a zipcode has been selected before proceeding with call flow, by: - If a get param is sent, store it and return. - If the context already has a zipcode, return. - If a language choice was passed back, pull it out of settings, store it and return. - If nothing was sent, prompt the user with available choices. This only needs to be set once during the life of a call. """ # Twimlet use if 'zipcode' in g.request_params.keys(): write_context('zipcode', g.request_params['zipcode']) # Internal app use if not get_zip(): errors = [] r = twiml.Response() # Collect and wipe digits if a choice was submitted if 'Digits' in g.request_params.keys(): sel = g.request_params.get('Digits') if len(sel) == 5: write_context('zipcode', sel) elif sel == '9': r.redirect(url_for('.index')) return r else: errors.append('%s is not a valid zip code, please try again.' % sel) del g.request_params['Digits'] # Prompt and gather if zip is not valid or no choice was submitted if not get_zip(): if request.path.startswith(url_for('.member')): reason = 'To help us identify your representatives,' elif request.path.startswith(url_for('.voting')): reason = 'To help us find your election office,' else: reason = None with r.gather(numDigits=5, timeout=settings.INPUT_TIMEOUT) as rg: if len(errors): rg.say(' '.join(errors)) if reason: rg.say(reason) rg.say("""please use the telephone keypad to enter your five-digit zip code now.""") r.redirect(request.path) return r return True
def search_bills(): """Search route for bills""" r = twiml.Response() if 'Digits' in g.request_params.keys(): # Go back to previous menu if 0 if g.request_params['Digits'] == '0': r.redirect(url_for('.bills')) return r bills = data.bill_search(int(g.request_params['Digits'])) if bills: query = {} if len(bills) == 1: query.update(bill_id=bills[0].bill_id) r.redirect(url_for('.bill', **query)) return r write_context('bills', bills) with r.gather(numDigits=1, timeout=settings.INPUT_TIMEOUT, action=url_for('.select_bill', **query)) as rg: rg.say("Multiple bills were found.") rg.say("Please select from the following:") for i, bill in enumerate(bills): bill['bill_context']['button'] = i + 1 rg.say("Press {button} for {bill_type} {bill_number}, {bill_title}".format(**bill['bill_context'])) rg.say("Press 0 to search for another number.") return r else: r.say('No bills were found matching that number.') with r.gather(timeout=settings.INPUT_TIMEOUT) as rg: rg.say("""Enter the number of the bill to search for, followed by the pound sign. Exclude any prefixes such as H.R. or S.""") rg.say("""To return to the previous menu, press 0, followed by the pound sign.""") r.redirect(url_for('.search_bills')) return r
def language_selection(): """Ensures a language has been selected before proceeding with call flow, by: - If a get param is sent, store it and return. - If the context already has a language, return. - If a language choice was passed back, pull it out of settings, store it and return. - If nothing was sent, prompt the user with available choices. This only needs to be set once during the life of a call. """ # Twimlet-style params always override language settings if 'language' in g.request_params.keys(): sel = g.request_params['language'] try: sel = int(sel) write_context('language', settings.LANGUAGES[sel - 1][0]) except ValueError: if sel in [lang[0] for lang in settings.LANGUAGES]: write_context('language', sel) # Internal app use if not get_lang(): errors = [] r = twiml.Response() # Collect and wipe digits if a choice was submitted if 'Digits' in g.request_params.keys(): sel = int(g.request_params.get('Digits', 1)) try: write_context('language', settings.LANGUAGES[sel - 1][0]) except: errors.append('%d is not a valid selection, please try again.') del g.request_params['Digits'] # Prompt and gather if language is not valid or no choice was submitted if not get_lang(): with r.gather(numDigits=1, timeout=settings.INPUT_TIMEOUT) as rg: if not len(errors): rg.say("""Welcome to Call on Congress, the Sunlight Foundation's free service that helps you keep our lawmakers accountable. """) else: rg.say(' '.join(errors)) rg.say('Press 1 to continue in English.', language='en') rg.say('Presione 2 para continuar en espanol.', language='es') r.redirect(request.path) return r return True
def load_members_for(zipcode): legislators = data.legislators_for_zip(zipcode) write_context('legislators', legislators) return legislators