Created
August 19, 2013 19:59
-
-
Save bchartoff/6273385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from datetime import datetime | |
import time | |
def parse_date(date): | |
return datetime.strptime(date, "%Y-%m-%d").date() | |
count = 0 | |
leg_count = 0 | |
old_ends = [] | |
current_leg = json.load(open("legislators-current.json")) | |
current_ids = [] | |
for c_leg in current_leg: | |
new_leg = True | |
first = True | |
for term in c_leg['terms']: | |
if first: | |
first = False | |
old_start = parse_date(term['start']) | |
old_end = parse_date(term['end']) | |
continue | |
else: | |
new_start = parse_date(term['start']) | |
new_end = parse_date(term['end']) | |
diff = (new_start-old_end).days | |
if diff%365 > 60 and new_start.month == 1: | |
count += 1 | |
if new_leg: | |
leg_count += 1 | |
new_leg = False | |
print "" | |
print c_leg['name']['official_full'] | |
print "term N end " + str(old_end) | |
print "term N+1 start " + str(new_start) | |
print "gap % 365: " + str(diff%365) | |
old_ends.append(old_end) | |
old_start = new_start | |
old_end = new_end | |
print "\n%i gaps for %i legislators and %i unique end dates" %(count, leg_count,len(list(set(old_ends)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment