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 court_list(court_type, court_name, miles): courts = list(Database.find_courts(court_type, court_name, int(miles))) return jsonify(courts=courts)
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)
def add_search_name_tasks(name): Database.insert_tasks('circuit', name.upper()) Database.insert_tasks('district', name.upper()) return ''
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']
'ProgramType', 'Military' ] excluded_fields = [ '_id', 'details', 'details_fetched', 'case_number', 'details_fetched_for_hearing_date', 'Hearings', 'defendant' ] def get_db_connection(): return pymongo.MongoClient(os.environ['MONGO_DB'])['va_court_search'] db = get_db_connection() courts = list(Database.get_circuit_courts()) courts_by_fips = {court['fips_code']: court for court in courts} cases_by_court = {} def write_cases_to_file(cases, filename, details, exclude_cases): with open('./' + filename + '.csv', 'w') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=sorted(fieldnames)) writer.writeheader() for case in cases: if case['case_number'] in exclude_cases: continue if 'error' in case['details']: print 'Error getting case details', case['case_number'] continue
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]
.replace("Sheriff's Office", "") \ .replace("Sheriffs Office", "") \ .replace("PD", "") \ .replace("Pd", "") \ .replace("Police Dept.", "") \ .replace("Police Dept", "") \ .replace("Division of Police", "") \ .replace("Police", "") \ .replace("/ Security", "") \ .replace("& ", "") \ .strip() geolocator_google = GoogleV3(api_key='AIzaSyApqcChB-VAfVx3KqzfW2NvYAfHFyrxRuc') geolocator_osm = Nominatim() courts = list(Database.get_circuit_courts()) court_names = [court['name'] for court in courts] rows = [] with open(sys.argv[1]) as csvfile: reader = csv.DictReader(csvfile) for row in reader: rows.append(row) fieldnames = rows[0].keys() agencies = [key for key, group in groupby(rows, lambda x: x['agency'])] agencies_to_court = {} sanitized_agencies_to_court = {} for agency in agencies: sanitized_agency = sanitize_agency(agency) if sanitized_agency in sanitized_agencies_to_court:
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]
'RestrictionEndDate', 'VAAlcoholSafetyAction', 'ProgramType', 'Military' ] excluded_fields = [ '_id', 'details', 'details_fetched', 'case_number', 'details_fetched_for_hearing_date', 'Hearings', 'defendant' ] def get_db_connection(): return pymongo.MongoClient(os.environ['MONGO_DB'])['va_court_search'] db = get_db_connection() courts = list(Database.get_circuit_courts()) courts_by_fips = {court['fips_code']:court for court in courts} cases_by_court = {} def write_cases_to_file(cases, filename, details, exclude_cases): with open('./' + filename + '.csv', 'w') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=sorted(fieldnames)) writer.writeheader() for case in cases: if case['case_number'] in exclude_cases: continue if 'error' in case['details']: print 'Error getting case details', case['case_number'] continue case['Court'] = courts_by_fips[case['court_fips']]['name']
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'] search_terms += 1 print name, len(courts_to_search), 'courts' for fips_code in courts_to_search: