예제 #1
0
    def read(self, request):
        try:
            latitude, longitude = request.GET['lat'], request.GET['long']
        except KeyError:
            resp = rc.BAD_REQUEST
            resp.write(': Need lat and long parameters')
            return resp

        url = "%sboundary/?contains=%s,%s&sets=sldl,sldu&limit=0" % (
            self.base_url, latitude, longitude)

        resp = json.load(urllib2.urlopen(url))

        filters = []
        ret = []
        for dist in resp['objects']:
            state = dist['name'][0:2].lower()
            chamber = {
                '/1.0/boundary-set/sldu/': 'upper',
                '/1.0/boundary-set/sldl/': 'lower'
            }[dist['set']]
            census_name = dist['name'][3:]

            our_name = district_from_census_name(state, chamber, census_name)

            filters.append({
                'state': state,
                'district': our_name,
                'chamber': chamber
            })

        if not filters:
            return []

        return list(db.legislators.find({'$or': filters}))
예제 #2
0
    def read(self, request):
        try:
            latitude, longitude = request.GET['lat'], request.GET['long']
        except KeyError:
            resp = rc.BAD_REQUEST
            resp.write(': Need lat and long parameters')
            return resp

        url = "%sboundary/?contains=%s,%s&sets=sldl,sldu&limit=0" % (
            self.base_url, latitude, longitude)

        resp = json.load(urllib2.urlopen(url))

        filters = []
        for dist in resp['objects']:
            state = dist['name'][0:2].lower()
            chamber = {'/1.0/boundary-set/sldu/': 'upper',
                       '/1.0/boundary-set/sldl/': 'lower'}[dist['set']]
            census_name = dist['name'][3:]

            our_name = district_from_census_name(
                state, chamber, census_name)

            filters.append({'state': state, 'district': our_name,
                            'chamber': chamber})

        if not filters:
            return []

        return list(db.legislators.find({'$or': filters},
                                        _build_field_list(request)))
예제 #3
0
    def read(self, request):
        latitude, longitude = request.GET.get("lat"), request.GET.get("long")

        if not latitude or not longitude:
            resp = rc.BAD_REQUEST
            resp.write(": Need lat and long parameters")
            return resp

        url = "%sboundary/?contains=%s,%s&sets=sldl,sldu&limit=0" % (self.base_url, latitude, longitude)

        resp = json.load(urllib2.urlopen(url))

        filters = []
        for dist in resp["objects"]:
            state = dist["name"][0:2].lower()
            chamber = {"/1.0/boundary-set/sldu/": "upper", "/1.0/boundary-set/sldl/": "lower"}[dist["set"]]
            census_name = dist["name"][3:]

            our_name = district_from_census_name(state, chamber, census_name)

            filters.append({"state": state, "district": our_name, "chamber": chamber})

        if not filters:
            return []

        return list(db.legislators.find({"$or": filters}, _build_field_list(request)))
예제 #4
0
def test_district_from_census_name():
    tests = [(('vt', 'lower', 'Washington-5 State House District'),
              'Washington-5'), (('ca', 'lower', 'Assembly District 6'), '6'),
             (('mn', 'lower', 'State House District 9A'), '09A'),
             (('nv', 'uper', 'State Senatorial District 7'), '7'),
             (('vt', 'lower', 'Orleans-Franklin-1 State House District'),
              'Orleans-Franklin-1'),
             (('nv', 'upper', 'Capital Senatorial District'),
              'Capital Senatorial District'),
             (('nv', 'upper', 'Central Nevada Senatorial District'),
              'Central Nevada Senatorial District'),
             (('vt', 'upper', 'Rutland State Senate District'), 'Rutland'),
             (('ex', 'lower', 'Senate District 8B'), '8B')]

    for census, ours in tests:
        assert utils.district_from_census_name(*census) == ours
예제 #5
0
def test_district_from_census_name():
    tests = [
        (('vt', 'lower', 'Washington-5 State House District'),
         'Washington-5'),
        (('ca', 'lower', 'Assembly District 6'), '6'),
        (('mn', 'lower', 'State House District 9A'), '09A'),
        (('nv', 'uper', 'State Senatorial District 7'), '7'),
        (('vt', 'lower', 'Orleans-Franklin-1 State House District'),
         'Orleans-Franklin-1'),
        (('nv', 'upper', 'Capital Senatorial District'),
         'Capital Senatorial District'),
        (('nv', 'upper', 'Central Nevada Senatorial District'),
         'Central Nevada Senatorial District'),
        (('vt', 'upper', 'Rutland State Senate District'),
         'Rutland'),
        (('ex', 'lower', 'Senate District 8B'), '8B')]

    for census, ours in tests:
        assert utils.district_from_census_name(*census) == ours