python-capitolwords 0.3.0
Libraries for interacting with the Capitol Words API
Python library for interacting with Capitol Words API.
Capitol Words provides access to the most commonly used words in Congressional Record each day. (http://www.capitolwords.org/api/)
python-capitolwords is a project of Sunlight Labs (c) 2009 Written by James Turk <jturk@sunlightfoundation.com>.
All code is under a BSD-style license, see LICENSE for details.
Homepage: http://pypi.python.org/pypi/python-capitolwords/
Source: http://github.com/sunlightlabs/python-capitolwords/
Requirements
python >= 2.4
simplejson >= 1.8 (not required with python 2.6, will use built in json module)
Installation
To install run
python setup.py install
which will install the bindings into python's site-packages directory.
Usage
All that is required to start using the API is for it to be imported, no API key is required for Capitol Words.
Import capitolwords:
>>> import capitolwords
- All Capitol Words API methods return a WordResult object with three attributes:
- word - a word in question
- word_date - a particular date [not available for lawmaker]
- word_count - the number of times word was said
dailysum
dailysum(word, year, month=None, day=None, endyear=None, endmonth=None, endday=None)
dailysum returns a list of records given a word and a series of days.
Using dailysum to find out how many times 'transparency' was said on May 22nd 2008:
>>> wr = capitolwords.dailysum('transparency', 2008, 5, 22)[0]
>>> print wr.word_count
47
Using dailysum to find out how many times 'transparency' was said in May 2008:
>>> for wr in capitolwords.dailysum('transparency', 2008, 5):
... print wr.word_date, wr.word_count
2008-05-23 3
2008-05-22 47
2008-05-21 13
2008-05-20 18
2008-05-19 25
2008-05-15 22
2008-05-14 22
2008-05-13 17
2008-05-12 10
2008-05-08 8
2008-05-07 11
2008-05-06 6
2008-05-05 1
2008-05-02 1
2008-05-01 11
Using dailysum to find out how many times 'transparency' was said for all days in a given range of days:
>>> for wr in capitolwords.dailysum('transparency', 2008, 4, 3, 2008, 4, 10):
... print wr.word_date, wr.word_count
2008-04-10 2
2008-04-09 8
2008-04-08 5
2008-04-07 4
2008-04-03 8
wordofday
dailysum(year=None, month=None, day=None, endyear=None, endmonth=None, endday=None, maxrows=1)
wordofday returns a list of records representing the most commonly used words for given dates.
Using wordofday to get the top 5 words for April 3rd, 2008:
>>> for w in capitolwords.wordofday(2008, 4, 3, maxrows=5): ... print w.word, w.word_count sergeant 1706 housing 1382 director 976 corporal 899 mortgage 868
Using wordofday to get the top words for every day in May 2008:
>>> for w in capitolwords.wordofday(2008, 5): ... print w.word, w.word_count, w.word_date conrad 3 2008-05-29 recess 3 2008-05-27 name 146 2008-05-23 defense 2411 2008-05-22 tax 1109 2008-05-21 assistance 1004 2008-05-20 assistance 645 2008-05-19 food 40 2008-05-16 iraq 586 2008-05-15 budget 756 2008-05-14 assistance 1402 2008-05-13 oil 546 2008-05-12 housing 1418 2008-05-08 insurance 591 2008-05-07 insurance 631 2008-05-06 day 95 2008-05-05 housing 82 2008-05-02 health 879 2008-05-01
Using wordofday to get the word of day across a given range:
>>> for w in capitolwords.wordofday(2008, 4, 3, 2008, 4, 10): ... print w.word, w.word_count, w.word_date energy 465 2008-04-10 health 380 2008-04-09 energy 265 2008-04-08 housing 540 2008-04-07 energy 244 2008-04-04 sergeant 1706 2008-04-03
lawmaker
lawmaker(lawmaker_id, year=None, month=None, day=None, endyear=None, endmonth=None, endday=None, maxrows=1)
lawmaker returns a list of records representing a lawmakers most said words
lawmakers are referenced by their Bioguide ID. Bioguide IDs can be obtained from the Sunlight Labs API.
[Note: the word_date attribute of the records is not populated as it does not apply to this method]
Using lawmaker to get the words Mitch McConnell said the most on October 10th, 2008:
>>> for w in capitolwords.lawmaker('M000355', 2008, 12, 12, maxrows=5):
... print w.word, w.word_count
dole 23
women 16
elizabeth 13
included 11
north 11
Using lawmaker to get the words Mitch McConnell said the most across a given range:
>>> for w in capitolwords.lawmaker('M000355', 2008, 4, 3, 2008, 4, 10, maxrows=5):
... print w.word, w.word_count
lance 24
home 21
iraq 21
colombia 19
nominee 17
| File | Type | Py Version | Uploaded on | Size | # downloads |
|---|---|---|---|---|---|
| python-capitolwords-0.3.0.tar.gz (md5) | Source | 2009-01-30 | 4KB | 473 | |
- Author: James Turk
- Home Page: http://github.com/sunlightlabs/python-capitolwords/
-
License:
BSD-style license ================= Copyright (c) 2008, Sunlight Labs All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sunlight Labs nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - Platform: any
- Categories
- Package Index Owner: jamesturk
- DOAP record: python-capitolwords-0.3.0.xml
