Skip to content

Commit fe553e8

Browse files
author
Paul Tagliamonte
committed
Playing with some congress ideas.
1 parent a16d790 commit fe553e8

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

examples/congress/ma_legs

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/congress/who_is_my_rep

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
from sunlight import congress
5+
import json
6+
import os
7+
8+
obj = json.load(open(os.path.expanduser("~/.location.json"), "r"))
9+
lat, lon = obj['latitude'], obj['longitude']
10+
11+
12+
print(congress.locate_legislators_by_zip("02481"))

sunlight/services/congress.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ class Congress(sunlight.service.Service):
2222
def legislators(self, **kwargs):
2323
return self.get('legislators', **kwargs)
2424

25+
def locate_legislators_by_lat_lon(self, lat, lon, **kwargs):
26+
kwargs.update({
27+
"latitude": lat,
28+
"longitude": lon
29+
})
30+
return self.get('legislators/locate', **kwargs)
31+
32+
def locate_legislators_by_zip(self, zipcode, **kwargs):
33+
kwargs.update({
34+
"zip": zipcode
35+
})
36+
return self.get('legislators/locate', **kwargs)
37+
2538
# implementation methods
2639
def _get_url(self, endpoint, apikey, **kwargs):
2740
return "%s/%s?apikey=%s&%s" % (
2841
API_ROOT, endpoint, apikey,
2942
sunlight.service.safe_encode(kwargs)
3043
)
3144

45+
3246
def _decode_response(self, response):
3347
return json.loads(response)['results']

0 commit comments

Comments
 (0)