|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +from __future__ import unicode_literals |
| 4 | +from pprint import pprint |
| 5 | +import urllib2 |
| 6 | +import simplejson as json |
| 7 | + |
| 8 | +#user_local_data = json.load(urllib2.urlopen('http://freegeoip.net/json/')) |
| 9 | +user_local_data = json.load(urllib2.urlopen('http://api.ipinfodb.com/v3/ip-city/?key=a648bf3844359d401197bcaa214dd01e0f8c0c6d623ec57f3716fbcafc8262bd&format=json')) |
| 10 | + |
| 11 | +user_lat = user_local_data['latitude'] |
| 12 | +user_long = user_local_data['longitude'] |
| 13 | + |
| 14 | +#print gathered lat/long |
| 15 | +#print user_lat,user_long |
| 16 | + |
| 17 | +#print """ |
| 18 | +# |
| 19 | +#You can get your latitude and longitude from http://www.latlong.net/ |
| 20 | +# |
| 21 | +#""" |
| 22 | + |
| 23 | +#user_lat = raw_input('Please enter your Latitude: \n') |
| 24 | +#user_long = raw_input('Please enter your Longitude: \n') |
| 25 | + |
| 26 | +#user_lat = '47.653098' |
| 27 | +#user_long = '-122.353731' |
| 28 | + |
| 29 | +lat_long_url = 'https://congress.api.sunlightfoundation.com/districts/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long) |
| 30 | + |
| 31 | +congressional_district = json.load(urllib2.urlopen(lat_long_url)) |
| 32 | + |
| 33 | + |
| 34 | +legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) |
| 35 | + |
| 36 | +for i in legislators['results']: |
| 37 | + print i['last_name'] + ' ' + i['bioguide_id'] |
| 38 | + |
| 39 | +#All Legislators, irrespective of location |
| 40 | + |
| 41 | +#House only |
| 42 | +#legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators?chamber=house&per_page=all&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) |
| 43 | + |
| 44 | +#All Legislators |
| 45 | +#legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators?per_page=all&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long))) |
| 46 | + |
| 47 | +#print 'Based on the latitude and longitude provided, your United States Congresspeople are: \n' |
| 48 | + |
| 49 | + |
| 50 | +#Prints Congressman/Congresswoman + First, Last |
| 51 | + |
| 52 | +def find_legislators(): |
| 53 | + |
| 54 | + for i in legislators['results']: |
| 55 | + print i['last_name'] + ' ' + i['bioguide_id'] |
| 56 | + #legislator_ids.append(i) |
| 57 | + |
| 58 | +#find_legislators() |
| 59 | + |
| 60 | +#votes_url = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/votes?voter_ids.{}__exists=true&apikey=15f4679bdc124cd6a2c6be8666253000')).format( __ THIS IS WHERE THE UNIQUE ID OF THE LEGISLATOR NEEDS TO BE __ ) |
| 61 | + |
| 62 | +#pprint(votes_url) |
| 63 | + |
| 64 | +#def recent_votes(): |
| 65 | + |
| 66 | + ##THIS IS WHERE YOU ARE GOING TO RETURN THE LAST 10 VOTES BY var = LEGISLATOR |
| 67 | + |
| 68 | +def print_legislators(): |
| 69 | + |
| 70 | + for i in legislators['results']: |
| 71 | + |
| 72 | + if i['chamber'] == 'house' and i['gender'] == 'M': |
| 73 | + print 'Congressman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) |
| 74 | + if i['chamber'] == 'house' and i['gender'] == 'F': |
| 75 | + print 'Congresswoman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) |
| 76 | + elif i['chamber'] == 'senate': |
| 77 | + print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] ) |
| 78 | + |
| 79 | +#print_legislators() |
0 commit comments