<commit_before>""" 
  Python library for interacting with the CRP API based on <NAME>'
  Python CRP API (https://code.google.com/archive/p/python-crpapi/downloads)

  The CRP API (http://www.opensecrets.org/action/api_doc.php) provides campaign 
  finance and other data from the Center for Responsive Politics.

  Example usage:
  >>> print CRP.candSummary.get(cid='N00007360',cycle='2016')
  {u'origin': u'Center for Responsive Politics', u'next_election': u'2016', u'debt': u'0', 
  u'last_updated': u'12/31/2016', u'cand_name': u'<NAME>', u'cid': u'N00007360', 
  u'spent': u'3478460.87', u'chamber': u'H', u'state': u'CA', u'first_elected': u'1987', 
  u'source': u'http://www.opensecrets.org/politicians/summary.php?cid=N00007360&cycle=2016', 
  u'party': u'D', u'total': u'4318118.79', u'cash_on_hand': u'1820817.85', u'cycle': u'2016'}
"""

import urllib, urllib2
import json

class CRPApiError(Exception):
    """ Exception for CRP API errors """

# results #
class CRPApiObject(object):
    def __init__(self, d):
        self.__dict__ = d

# namespaces #
class CRP(object):

    apikey = None

    @staticmethod
    def _apicall(func, params):
        if CRP.apikey is None:
            raise CRPApiError('Missing CRP apikey')

        url = 'https://www.opensecrets.org/api/?method=%s&output=json&apikey=%s&%s' % \
              (func, CRP.apikey, urllib.urlencode(params))
        headers = { 'User-Agent' : 'Mozilla/5.0' }

        try:
            request = urllib2.Request(url, None, headers)
            response = urllib2.urlopen(request).read()
            return json.loads(response)['response']
        except urllib2.HTTPError, e:
            raise CRPApiError(e.read())
        except (ValueError, KeyError), e:
            raise CRPApiError('Invalid Response')

    class candSummary(object):
        @staticmethod
        def get(**kwargs):
            result = CRP._apicall('candSummary', kwargs)['summary']
            return result['@attributes']

    class candContrib(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('candContrib', kwargs)['contributors']['contributor']
            return results

    class candIndustry(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('candIndustry', kwargs)['industries']['industry']
            return results

    class candSector(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('candSector', kwargs)['sectors']['sector']
            return results

    class candIndByInd(object):
        @staticmethod
        def get(**kwargs):
            result = CRP._apicall('CandIndByInd', kwargs)['candIndus']
            return result['@attributes']

    class memTravelTrips(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('memTravelTrips', kwargs)['trips']['trip']
            return results<commit_msg>added getLegislators class to CRP API<commit_after>""" 
  Python library for interacting with the CRP API based on <NAME>'
  Python CRP API (https://code.google.com/archive/p/python-crpapi/downloads)

  The CRP API (http://www.opensecrets.org/action/api_doc.php) provides campaign 
  finance and other data from the Center for Responsive Politics.

  Example usage:
  >>> print CRP.candSummary.get(cid='N00007360',cycle='2016')
  {u'origin': u'Center for Responsive Politics', u'next_election': u'2016', u'debt': u'0', 
  u'last_updated': u'12/31/2016', u'cand_name': u'<NAME>', u'cid': u'N00007360', 
  u'spent': u'3478460.87', u'chamber': u'H', u'state': u'CA', u'first_elected': u'1987', 
  u'source': u'http://www.opensecrets.org/politicians/summary.php?cid=N00007360&cycle=2016', 
  u'party': u'D', u'total': u'4318118.79', u'cash_on_hand': u'1820817.85', u'cycle': u'2016'}
"""

import urllib, urllib2
import json

class CRPApiError(Exception):
    """ Exception for CRP API errors """

# results #
class CRPApiObject(object):
    def __init__(self, d):
        self.__dict__ = d

# namespaces #
class CRP(object):

    apikey = None

    @staticmethod
    def _apicall(func, params):
        if CRP.apikey is None:
            raise CRPApiError('Missing CRP apikey')

        url = 'https://www.opensecrets.org/api/?method=%s&output=json&apikey=%s&%s' % \
              (func, CRP.apikey, urllib.urlencode(params))
        headers = { 'User-Agent' : 'Mozilla/5.0' }

        try:
            request = urllib2.Request(url, None, headers)
            response = urllib2.urlopen(request).read()
            return json.loads(response)['response']
        except urllib2.HTTPError, e:
            raise CRPApiError(e.read())
        except (ValueError, KeyError), e:
            raise CRPApiError('Invalid Response')

    class candSummary(object):
        @staticmethod
        def get(**kwargs):
            result = CRP._apicall('candSummary', kwargs)['summary']
            return result['@attributes']

    class candContrib(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('candContrib', kwargs)['contributors']['contributor']
            return results

    class candIndustry(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('candIndustry', kwargs)['industries']['industry']
            return results

    class candSector(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('candSector', kwargs)['sectors']['sector']
            return results

    class candIndByInd(object):
        @staticmethod
        def get(**kwargs):
            result = CRP._apicall('CandIndByInd', kwargs)['candIndus']
            return result['@attributes']

    class getLegislators(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('getLegislators', kwargs)['legislator']
            return results

    class memTravelTrips(object):
        @staticmethod
        def get(**kwargs):
            results = CRP._apicall('memTravelTrips', kwargs)['trips']['trip']
            return results
{'fraction_non_alphanumeric': 0.1419672131147541, 'fraction_numerical': 0.02819672131147541, 'mean_word_length': 2.923472668810289, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7005191', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1901, 'n_words': 404}