コード例 #1
0
import csv
import sys
from courtutils.database import Database

courts = list(Database.get_circuit_courts())
courts_by_name = {court['name']: court for court in courts}


def get_nearby_courts(court_name):
    if 'nearbyCourts' not in courts_by_name[court_name]:
        print 'LOOKING UP COURTS NEAR', court_name
        nearby_courts = Database.find_courts('circuit', court_name, 40)
        courts_by_name[court_name]['nearbyCourts'] = \
            [court['fips_code'] for court in nearby_courts]
    return courts_by_name[court_name]['nearbyCourts']


def get_courts_to_search(row, courts_by_name):
    if 'courtName' not in row or row['courtName'] not in courts_by_name:
        return [court['fips_code'] for court in courts]
    return get_nearby_courts(row['courtName'])


search_id = Database.insert_search()
search_terms = 0
search_tasks = []
with open(sys.argv[1]) as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        courts_to_search = get_courts_to_search(row, courts_by_name)
        name = row['last'] + ', ' + row['first']
コード例 #2
0
def court_map():
    circuit_courts = list(Database.get_circuit_courts())
    district_courts = list(Database.get_district_courts())
    return render_template('courtmap.html',
        circuit_courts=circuit_courts,
        district_courts=district_courts)
コード例 #3
0
def clean_names(case, field):
    case[field] = ' '.join(case[field].split())
    name_parts = case[field].split(': ')
    case[name_parts[0]] = name_parts[1]

excluded_fields = [
    '_id', 'details', 'details_fetched', 'case_number',
    'status', 'name', 'other_name', 'search_id', 'fetched'
]

force_fieldnames = [
    'Plaintiff2', 'Plaintiff3', 'Defendant2', 'Defendant3', 'FilingFeePaid'
]

courts = list(Database.get_circuit_courts())
courts_by_fips = {court['fips_code']:court for court in courts}
fieldnames = None
writer = None

with open('./data.csv', 'w') as csvfile:
    for case in Database.get_all_cases():
        clean_names(case, 'name')
        clean_names(case, 'other_name')
        case['Status'] = case['status']
        case['Court'] = courts_by_fips[case['fips_code']]['name']
        for detail in case['details']:
            new_key = detail.replace(' ', '')
            if new_key == 'Plaintiff': new_key += '1'
            if new_key == 'Defendant': new_key += '1'
            case[new_key] = case['details'][detail]