Skip to content
Sergei Wallace edited this page Dec 5, 2015 · 3 revisions

WikiCode Documentation

Legislator Events

The Legislator Events tools are a small collection of scripts that allow users to execute a number of tasks for creating JSON objects containing data about all of the legislative actions taken by a given legislator. This data is the then consumed by the timeline to visualize these actions.

Tasks are executed by passing the task name to the run script along with any required options

./run TASK_NAME --OPTIONS

Additional task can be added by simply by creating new modules in the tasks folder. They do, however, need to have a run method to be executable by the run script. Options are passed into the run method as a python dict.

There are three available tasks:

List Legislators

Lists the current legislators available for creating data objects. Takes a --chamber="CHAMBER" option. Chambers are either 'house' or 'senate'.

List Events

Lists the events available to include in the legislator objects. Requires no options

Legislator Events

The main task which creates the legislator JSON. Takes a --legislator="LEGISLATOR_NAME" option. The legislator name must match the name in the legislators yaml, so if an error is returned use the List Legislators task to find the name of the desired legislator.

The Legislator Events module is essentially a single, large class with methods for adding the different legislator events. There is one additional method used determine which of legislator-event data-gathering methods are called.

For example, the class contains an 'add_terms' method, which creates events for each time a legislator was elected to office for a new term.

    def add_terms(self):
        """ add selected legislators terms to the events object"""
        for term in self.legislator["terms"][:-1]:
            t = str(int(time.mktime(
                time.strptime(term["start"], '%Y-%m-%d'))))
            cong_sess = { 
                "time" : t, 
                "event" : "start congressional term",
                "event_type" : "start_congressional_term",
                "info" : term, 
                "event_id" : str(uuid.uuid4()) 
            }
            self.legis_list.append(cong_sess)

Term data is added to the final JSON when this method is called by the 'create_object' method.

    def create_object(self):
        for event in self.events:
            event()

To add more data to the final json object, simply add the method which pulls in the data and formats the event to the class, and add the methods name to the events list in the class' init function.

   self.events = [
        self.add_terms,
        self.add_sponsored_bills, self.add_parties,
        self.add_cosponsored_bills, self.add_committee_memberships,
        self.add_campaign_contributions, self.add_speeches,
        self.add_votes
    ]