Skip to content

Commit 8869c1a

Browse files
author
saschwafel
committed
Final commit of project files.
1 parent 082c2ec commit 8869c1a

File tree

4 files changed

+159
-46
lines changed

4 files changed

+159
-46
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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()

Students/SSchwafel/Project/InformedVoter.py

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,77 @@
22

33
from __future__ import unicode_literals
44
from pprint import pprint
5-
import urllib2
65
import simplejson as json
6+
import sys
7+
import urllib2
8+
9+
#This allows printing to the console, including being able to pipe ( | ) the input
10+
reload(sys)
11+
sys.setdefaultencoding("utf-8")
712

8-
#user_local_data = json.load(urllib2.urlopen('http://freegeoip.net/json/'))
13+
#Making sure that there is at least one command line argument, if not, is none
14+
if len(sys.argv) == 1:
15+
command_line_argument = None
16+
else:
17+
command_line_argument = sys.argv[1]
18+
19+
#Finds out the user's IP address for lookup
920
user_local_data = json.load(urllib2.urlopen('http://api.ipinfodb.com/v3/ip-city/?key=a648bf3844359d401197bcaa214dd01e0f8c0c6d623ec57f3716fbcafc8262bd&format=json'))
1021

22+
#Set variables for detected lat/long
1123
user_lat = user_local_data['latitude']
1224
user_long = user_local_data['longitude']
1325

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-
26+
#lat_long_url = 'https://congress.api.sunlightfoundation.com/districts/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long)
3327

28+
#Look up legislators from API with given lat/long, then store in a var. for later use
3429
legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long)))
3530

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
5131

32+
#Remnant of abandoned functionality
5233
def find_legislators():
53-
34+
"""This function returns the legislator's last name and unique bioguide id, this would be useful for further, unimplemented features"""
5435
for i in legislators['results']:
55-
print i['last_name'] + ' ' + i['bioguide_id']
56-
#legislator_ids.append(i)
36+
print '{} {}'.format(i['last_name'], i['bioguide_id'])
5737

58-
#find_legislators()
38+
def print_all_legislators():
39+
"""This function prints all the legislators, then formats according to gender and title"""
40+
41+
legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators?per_page=all&apikey=15f4679bdc124cd6a2c6be8666253000'))
42+
for i in legislators['results']:
5943

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 __ )
44+
if i['chamber'] == 'house' and i['gender'] == 'M':
45+
print 'Congressman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] )
46+
if i['chamber'] == 'house' and i['gender'] == 'F':
47+
print 'Congresswoman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] )
48+
elif i['chamber'] == 'senate':
49+
print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] )
6150

62-
#pprint(votes_url)
51+
def print_manual_legislators():
52+
"""This function prints the legislators of the given lat/long, then formats according to gender and title"""
53+
54+
print """
55+
56+
You can get your latitude and longitude from http://www.latlong.net/
57+
58+
"""
6359

64-
#def recent_votes():
60+
user_lat = raw_input('Please enter your Latitude: \n')
61+
user_long = raw_input('Please enter your Longitude: \n')
6562

66-
##THIS IS WHERE YOU ARE GOING TO RETURN THE LAST 10 VOTES BY var = LEGISLATOR
63+
legislators = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/legislators/locate?latitude={}&longitude={}&apikey=15f4679bdc124cd6a2c6be8666253000'.format(user_lat, user_long)))
64+
65+
for i in legislators['results']:
6766

68-
def print_legislators():
67+
if i['chamber'] == 'house' and i['gender'] == 'M':
68+
print 'Congressman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] )
69+
if i['chamber'] == 'house' and i['gender'] == 'F':
70+
print 'Congresswoman {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] )
71+
elif i['chamber'] == 'senate':
72+
print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] )
6973

74+
def print_detected_legislators():
75+
"""This function prints the legislators local to the IP address of the user, then formats according to gender and title"""
7076
for i in legislators['results']:
7177

7278
if i['chamber'] == 'house' and i['gender'] == 'M':
@@ -76,4 +82,13 @@ def print_legislators():
7682
elif i['chamber'] == 'senate':
7783
print 'Senator {} {} - {} \nPhone: {}\nWebsite: {}\n'.format(i['first_name'],i['last_name'],i['party'],i['phone'],i['website'] )
7884

79-
#print_legislators()
85+
if command_line_argument == '--all-legislators':
86+
print_all_legislators()
87+
88+
elif command_line_argument == None:
89+
print 'Based on the latitude and longitude detected, your United States Congresspeople are: \n'
90+
print_detected_legislators()
91+
92+
elif command_line_argument == '--manual':
93+
print_manual_legislators()
94+

Students/SSchwafel/Project/README

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
README
2+
======
3+
4+
Welcome to the Informed Voter app! Right now, it provides the following functionality:
5+
6+
Lists YOUR legislators based on an IP lookup, by running the program with no argument, these are returned
7+
8+
Listing ALL legislators currently in Congress (run with the command line argument --all-legislators
9+
10+
Finding out the representatives of a location via lat/long (access this functionality by running it with the --manual option)

Students/SSchwafel/Project/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
url = json.load(urllib2.urlopen('https://congress.api.sunlightfoundation.com/votes?fields=voters&apikey=15f4679bdc124cd6a2c6be8666253000'))
9+
pprint(url)

0 commit comments

Comments
 (0)