This file is indexed.

/usr/share/pyshared/sunlight/services/congress.py is in python-sunlight 1.1.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Copyright (c) Sunlight Labs, 2012 under the terms and conditions
# of the LICENSE file.

"""
.. module:: sunlight.services.congress
    :synopsis: Sunlight Congress API Implementation

Sunlight Congress API Implementation inside ``python-sunlight``.
"""

import sunlight.service
import json

service_url = "http://services.sunlightlabs.com/api/"

def _unpack(resp, key):
    return [e[key] for e in resp[key+'s']]

class congress(sunlight.service.Service):
    """
    Bindings into the `Sunlight Congress API
    <http://services.sunlightlabs.com/docs/Sunlight_Congress_API/>`_, an API
    primarily for details on current federal legislators.
    """

    def legislators(self, **kwargs):
        """
        Query for all legislators matching certain criteria.

        See documentation at `legislators.get(List)
        <http://services.sunlightlabs.com/docs/congressapi/legislators.get(List)/>`_
        """
        return _unpack(self.get('legislators.getList', **kwargs),
                       'legislator')


    def legislator_search(self, name, threshold=0.9, all_legislators=False):
        """
        Fuzzy-matching name search against federal legislators.

        See documentation at `legislators.search
        <http://services.sunlightlabs.com/docs/congressapi/legislators.search/>`_
        """
        params = {'name': name, 'threshold': threshold}
        if all_legislators:
            params['all_legislators'] = 1
        return _unpack(self.get('legislators.search', **params),
                       'result')


    def legislators_for_zip(self, zipcode):
        """
        Query for all legislators representing a given ZIP code.

        This method is not recommended, prefer legislators_for_lat_lon instead.
        See the blog post `"Don't Use Zip Codes Unless You Have To"
        <http://sunlightlabs.com/blog/2012/dont-use-zipcodes/>`_.

        See documentation at `legislators.allForZip
        <http://services.sunlightlabs.com/docs/congressapi/legislators.allForZip/>`_
        """
        return _unpack(self.get('legislators.allForZip', zip=zipcode),
                       'legislator'
                      )

    def legislators_for_lat_lon(self, latitude, longitude):
        """
        Query for all legislators representing an given location.

        See documentation at `legislators.allForLatLong
        <http://services.sunlightlabs.com/docs/congressapi/legislators.allForLatLong/>`_
        """
        return _unpack(self.get('legislators.allForLatLong', latitude=latitude,
                                longitude=longitude), 'legislator')

    def districts_for_zip(self, zipcode):
        """
        Query for all congressional districts overlapping a zip code.

        See documentation at `districts.getDistrictFromLatLong
        <http://services.sunlightlabs.com/docs/congressapi/districts.getDistrictFromLatLong/>`_
        """
        return _unpack(self.get('districts.getDistrictsFromZip', zip=zipcode),
                       'district'
                      )

    def districts_for_lat_lon(self, latitude, longitude):
        """
        Query for all congressional districts containing a given location.

        See documentation at `districts.getDistrictFromLatLong
        <http://services.sunlightlabs.com/docs/congressapi/districts.getDistrictFromLatLong/>`_
        """
        return _unpack(self.get('districts.getDistrictFromLatLong',
                                latitude=latitude, longitude=longitude),
                       'district'
                      )

    def committees(self, chamber):
        """
        Query for all committees for a chamber.  (House|Senate|Joint)

        See documentation at `committees.getList
        <http://services.sunlightlabs.com/docs/congressapi/committees.getList/>`_
        """
        return _unpack(self.get('committees.getList', chamber=chamber),
                       'committee')

    def committee_detail(self, id):
        """
        Query for all details for a committee, including members.

        See documentation at `committees.get
        <http://services.sunlightlabs.com/docs/congressapi/committees.get/>`_
        """
        return self.get('committees.get', id=id)['committee']

    def committees_for_legislator(self, bioguide_id):
        """
        Query for all details for all of a legislator's committee assignments.

        See documentation at `committees.allForLegislator
        <http://services.sunlightlabs.com/docs/congressapi/committees.allForLegislator/>`_
        """
        return _unpack(self.get('committees.allForLegislator',
                                bioguide_id=bioguide_id), 'committee')

    # implementation methods
    def _get_url(self, obj, apikey, **kwargs):
        return "%s/%s?apikey=%s&%s" % (
            service_url,
            obj,
            apikey,
            sunlight.service.safe_encode(kwargs)
        )

    def _decode_response(self, response):
        return json.loads(response)['response']