def call_election_office(): r = twiml.Response() zipcode = get_zip() offices = data.election_offices_for_zip(zipcode) if not len(offices): r.redirect('.voting') return r offices_with_phones = [office for office in offices if office.get('phone')] office = None if len(offices_with_phones) == 1: office = offices_with_phones[0] elif len(offices_with_phones) > 1: if 'Digits' in g.request_params.keys(): office = offices_with_phones[int(g.request_params.get('Digits')) - 1] else: with r.gather(numDigits=1, timeout=settings.INPUT_TIMEOUT) as rg: for i, office in enumerate(offices_with_phones): rg.say('Press %d to call %s at %s.' % (i + 1, office.get('authority_name'), office.get('phone'))) return r if office and office.get('phone'): r.say("Connecting you to your election office at") r.say(" %s" % office['phone']) with r.dial() as rd: rd.number(office['phone']) else: r.say("We're sorry, no phone number is available for this office.") flush_context('zipcode') return next_action(default=url_for('.voting')) return r
def voting(): r = twiml.Response() zipcode = get_zip() offices = data.election_offices_for_zip(zipcode) if not len(offices): r.say("""We were unable to find any offices for that zip code.""") flush_context('zipcode') r.redirect(url_for('.voting')) return r if 'Digits' in g.request_params.keys(): if g.request_params['Digits'] == '3': flush_context('zipcode') r.redirect(url_for('.voting')) return r return handle_selection(r, menu='voting', selection=g.request_params['Digits']) with r.gather(numDigits=1, timeout=settings.INPUT_TIMEOUT) as rg: if len(offices) > 1: rg.say("Multiple offices were found in your zip code.") rg.say("""Voter information, including polling place locations and how to register to vote, is available from:""") for office in offices: if office.get('authority_name'): rg.say(office['authority_name']) if office.get('street'): rg.say("Street address: %s, %s %s" % (office['street'], office['city'], office['state'])) if office.get('mailing_street'): rg.say("Mailing address: %s, %s %s, %s" % (office['mailing_street'], office['mailing_city'], office['state'], office['mailing_zip'])) if office.get('phone'): rg.say("Telephone number: %s" % office['phone']) if len([office.get('phone') for office in offices if office.get('phone')]): rg.say("Press 1 to call your election office.") rg.say("""Press 2 to repeat this information. Press 3 to enter a new zip code.""") rg.say("""To return to the previous menu, press 9.""") r.redirect(url_for('.voting')) return r