def test_method(): r = data.recent_votes({'bioguide_id': 'V000128'}) return str(r)
def handle_selection(selection): r = twiml.Response() if selection == '1': contribs = data.top_contributors(g.legislator) script = " ".join("%(name)s contributed $%(total_amount)s.\n" % c for c in contribs) r.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/1.wav') r.say(script) with r.gather(numDigits=1, timeout=10, action='/voice/next/2') as rg: rg.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/1-out.wav') elif selection == '2': votes = data.recent_votes(g.legislator) script = " ".join("On %(question)s. Voted %(voted)s. . The bill %(result)s.\t" % v for v in votes) r.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/2.wav') r.say("%s. %s" % (g.legislator['fullname'], script)) with r.gather(numDigits=1, timeout=10, action='/voice/next/3') as rg: rg.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/2-out.wav') elif selection == '3': bio = data.legislator_bio(g.legislator) r.say(bio or ('Sorry, we were unable to locate a biography for %s' % g.legislator['fullname'])) with r.gather(numDigits=1, timeout=10, action='/voice/next/4') as rg: rg.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/3-out.wav') elif selection == '4': comms = data.committees(g.legislator) r.say(g.legislator['fullname']) r.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/4.wav') r.say(comms) with r.gather(numDigits=1, timeout=10, action='/voice/next/5') as rg: rg.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/4-out.wav') elif selection == '5': # connect to the member's office r.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/5-pre.wav') r.say(g.legislator['fullname']) r.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/5-post.wav') with r.dial() as rd: rd.number(g.legislator['phone']) elif selection == '9': with r.gather(numDigits=1, timeout=10, action='/voice/signup') as rg: rg.play('http://assets.sunlightfoundation.com/projects/transparencyconnect/audio/9.wav') elif selection == '0': r.redirect('/voice/zipcode') else: r.say("I'm sorry, I don't recognize that selection. I will read you the options again.") r.redirect('/voice/reps') return r