Пример #1
0
def get_db_connection():
    if MONGO:
        return MongoDatabase('va_court_search', COURT_TYPE)
    if POSTGRES:
        return PostgresDatabase(COURT_TYPE)
    return None
fields_to_anonomize = [
    'Defendant', 'Name', 'AKA', 'AKA1', 'AKA2'
]

court_type = sys.argv[1]
if court_type != 'circuit' and court_type != 'district':
    raise ValueError('Unknown court type')

anonymize = True
if len(sys.argv) > 4 and sys.argv[4] == 'original':
    anonymize = False
print 'DATA NOT ANONYMIZED'

# connect to database
db = MongoDatabase('va_court_search', court_type)

courts = list(db.get_courts())
courts_by_fips = {court['fips_code']:court for court in courts}

s3 = boto3.resource('s3')

def simplify_time(time_string):
    time_string= time_string.replace(' Year(s)', 'Years ')\
                            .replace(' Month(s)', 'Months ')\
                            .replace(' Day(s)', 'Days ')
    days = 0
    string_parts = time_string.split(' ')
    for string_part in string_parts:
        if 'Years' in string_part:
            days += int(string_part.replace('Years','')) * 365
Пример #3
0
from courtreader import readers

MONGO = False
POSTGRES = True

if MONGO:
    import pymongo
    from courtutils.databases.mongo import MongoDatabase
if POSTGRES:
    from courtutils.databases.postgres import PostgresDatabase

#geolocator = GoogleV3(api_key=os.environ['GOOGLE_API_KEY'])

print 'CIRCUIT COURT'
circuit_db = None
if MONGO: circuit_db = MongoDatabase('va_court_search', 'circuit')
if POSTGRES: circuit_db = PostgresDatabase('circuit')
circuit_db.drop_courts()
reader = readers.CircuitCourtReader()
courts = reader.connect()
court_names = []
for fips, court in courts.iteritems():
    print court['name']
    court_locality = court['name'].replace(' Circuit Court', '')
    #location = geolocator.geocode(court_locality + ', Virginia, USA')
    circuit_db.add_court(court['name'], fips, None)
    court_names.append(court['name'] + ' ' + fips)
circuit_db.add_court_location_index()
circuit_db.commit()
'''
court_names.sort()
start_date = datetime.strptime(sys.argv[1], '%m/%d/%Y')
end_date = datetime.strptime(sys.argv[2], '%m/%d/%Y')
if start_date < end_date:
    raise ValueError('Start Date must be after End Date so they decend')

court_type = sys.argv[3]
if court_type != 'circuit' and court_type != 'district':
    raise ValueError('Unknown court type')

case_type = sys.argv[4]
if case_type != 'criminal' and case_type != 'civil':
    raise ValueError('Unknown case type')

# connect to database
db = None
if MONGO: db = MongoDatabase('va_court_search', court_type)
if POSTGRES: db = PostgresDatabase(court_type)

# get the courts to create tasks for
# check command line args for a specific court
courts = list(db.get_courts())
if len(sys.argv) > 5:
    courts = [court for court in courts if court['fips'] == sys.argv[5]]

# create the tasks
tasks = []
for court in courts:
    tasks.append({
        'fips': court['fips'],
        'start_date': start_date,
        'end_date': end_date,
    'OperatorLicenseSuspensionTime', 'ProbationTime'
]

fields_to_anonomize = ['Defendant', 'Name', 'AKA', 'AKA1', 'AKA2']

court_type = sys.argv[1]
if court_type != 'circuit' and court_type != 'district':
    raise ValueError('Unknown court type')

anonymize = True
if len(sys.argv) > 4 and sys.argv[4] == 'original':
    anonymize = False
print 'DATA NOT ANONYMIZED'

# connect to database
db = MongoDatabase('va_court_search', court_type)

courts = list(db.get_courts())
courts_by_fips = {court['fips_code']: court for court in courts}

s3 = boto3.resource('s3')


def simplify_time(time_string):
    time_string= time_string.replace(' Year(s)', 'Years ')\
                            .replace(' Month(s)', 'Months ')\
                            .replace(' Day(s)', 'Days ')
    days = 0
    string_parts = time_string.split(' ')
    for string_part in string_parts:
        if 'Years' in string_part:
if MONGO: from courtutils.databases.mongo import MongoDatabase
if POSTGRES: from courtutils.databases.postgres import PostgresDatabase

# get command line args
start_date = datetime.strptime(sys.argv[1],'%m/%d/%Y')
end_date = datetime.strptime(sys.argv[2],'%m/%d/%Y')
if start_date < end_date:
    raise ValueError('Start Date must be after End Date so they decend')

court_type = sys.argv[3]
if court_type != 'circuit' and court_type != 'district':
    raise ValueError('Unknown court type')

# connect to database
db = None
if MONGO: db = MongoDatabase('va_court_search', 'circuit')
if POSTGRES: db = PostgresDatabase('va_court_search', 'circuit')

# get the courts to create tasks for
# check command line args for a specific court
courts = list(db.get_courts())
if len(sys.argv) > 4:
    courts = [court for court in courts if court['fips'] == sys.argv[4]]

# create the tasks
tasks = []
for court in courts:
    tasks.append({
        'fips': court['fips'],
        'start_date': start_date,
        'end_date': end_date
import os
import pymongo
from geopy.geocoders import GoogleV3
from courtreader import readers

MONGO = False
POSTGRES = True

if MONGO: from courtutils.databases.mongo import MongoDatabase
if POSTGRES: from courtutils.databases.postgres import PostgresDatabase

geolocator = GoogleV3(api_key=os.environ['GOOGLE_API_KEY'])

print 'CIRCUIT COURT'
circuit_db = None
if MONGO: circuit_db = MongoDatabase('va_court_search', 'circuit')
if POSTGRES: circuit_db = PostgresDatabase('va_court_search', 'circuit')
circuit_db.drop_courts()
reader = readers.CircuitCourtReader()
courts = reader.connect()
court_names = []
for fips, court in courts.iteritems():
    print court['name']
    court_locality = court['name'].replace(' Circuit Court', '')
    location = geolocator.geocode(court_locality + ', Virginia, USA')
    circuit_db.add_court(court['name'], fips, location)
    court_names.append(court['name'] + ' ' + fips)
circuit_db.add_court_location_index()
circuit_db.commit()

'''