Skip to content

Commit b374428

Browse files
committed
Adding in the death-metal example from the blog
1 parent 71c4655 commit b374428

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/cross-api/death-metal

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2012, BSD-3 clause, Sunlight Labs
3+
4+
from sunlight import capitolwords
5+
from sunlight import congress
6+
7+
phrase = "death metal"
8+
# Today, we'll be printing out the Twitter IDs of all legislators that use
9+
# this phrase most in the congressional record.
10+
11+
for cw_record in capitolwords.phrases_by_entity(
12+
"legislator", # We're getting all legislators
13+
sort="count", # sorted by how much they say
14+
phrase=phrase, # this word
15+
)[:6]: # We'll just try the top 5 legislators
16+
legislator = congress.legislators(
17+
bioguide_id=cw_record['legislator'], # Look up this biogude (unique ID)
18+
# for every fed. legislator
19+
all_legislators="true" # search retired legislators
20+
)
21+
if len(legislator) >= 1: # If we were able to find the legislator
22+
legislator = legislator[0] # (this is a search, so it's a list)
23+
if legislator['twitter_id'] != "": # and they have a Twitter ID
24+
print "%s. %s (@%s) said %s %s times" % (
25+
legislator['title'],
26+
legislator['lastname'],
27+
legislator['twitter_id'],
28+
phrase,
29+
int(cw_record['count'])
30+
) # Print it to output :)

0 commit comments

Comments
 (0)