示例#1
0
def triage(directory, tempdir, output):
    """
    Read through a set of directories each containing records for a single person. Screen each person for obviously disqualifying elements in their record.
    """
    logging.basicConfig(level=logging.ERROR)
    if not os.path.exists(directory):
        logging.info(f"{directory} does not exist.")
        return
    subdirs = os.listdir(directory)
    recs = []
    logging.info(f"Constructing {len(subdirs)} records.")
    for sd in subdirs:
        rec = CRecord()
        pdfs = glob.glob(os.path.join(directory, sd, "*_Summary.pdf"))
        try:
            for pdf in pdfs: 
                try:
                    rec.add_summary(parse_pdf_summary(pdf, tempdir=tempdir))
                except:
                    try:
                        d, _ = Docket.from_pdf(pdf, tempdir=tempdir)
                        rec.add_docket(d)
                    except Exception as e:
                        raise e
            logging.info(f"Constructed a record for {rec.person.full_name()}, with {len(rec.cases)} cases.")
            recs.append((sd, rec))
        except Exception as e:
            logging.error(f"Error for {sd}: {str(e)}")
    logging.info(f"Now analyzing {len(recs)} records.")
    results = []
    for sd, rec in recs:
        
        res = {
                "dir": sd,
                "name": rec.person.full_name(),
                "cases": len(rec.cases),
                "felony_5_yrs": bool(any_felony_convictions_n_years(rec, 5)),
                "2plus_m1s_15yrs": bool(more_than_x_convictions_y_grade_z_years(rec, 2, "M1", 15)),
                "4plus_m2s_20yrs": bool(more_than_x_convictions_y_grade_z_years(rec, 4, "M2", 20)),
                "any_f1_convictions": not no_f1_convictions(rec),
        }
        res["any_disqualifiers"] = any([
            res["felony_5_yrs"],
            res["2plus_m1s_15yrs"],
            res["4plus_m2s_20yrs"],
            res["any_f1_convictions"],
        ])
        results.append(res)
    with open(output, 'w') as f:
        writer = csv.DictWriter(f, fieldnames=[
            "dir", "name", "cases", "felony_5_yrs", "2plus_m1s_15yrs", 
            "4plus_m2s_20yrs", "any_f1_convictions", "any_disqualifiers"])
        writer.writeheader()
        for res in results:
            writer.writerow(res)
    
    logging.info("Complete.")
示例#2
0
def dir(directory, archive, expungement_template, sealing_template, atty_name, atty_org, atty_org_addr, atty_org_phone, atty_bar_id, tempdir):
    if not os.path.exists(directory):
        print(f"The directory {directory} does not exist.")
        return
    files = [os.path.join(directory, f) for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
    summaries = []
    dockets = []
    atty = Attorney(full_name=atty_name, organization=atty_org, organization_address=atty_org_addr, organization_phone=atty_org_phone, bar_id=atty_bar_id)
    for f in files:
        print(f"  Processing {f}")
        try:
            dk = Docket.from_pdf(f, tempdir=tempdir)
            print(f"    It looks like {f} is a docket.")
            dockets.append(dk)
        except:
            try:
                sm = parse_pdf(f, tempdir=tempdir)
                print(f"    It looks like {f} is a summary.")
                summaries.append(sm)
            except:
                print(f"    It seems {f} is neither a summary nor a docket.")
    
    crec = CRecord()
    [crec.add_summary(summary) for summary in summaries]
    [crec.add_docket(docket) for docket in dockets]

    analysis = (
        Analysis(crec)
        .rule(expunge_deceased)
        .rule(expunge_over_70)
        .rule(expunge_nonconvictions)
        .rule(expunge_summary_convictions)
        .rule(seal_convictions)
    )

    petitions = [petition for decision in analysis.decisions for petition in decision.value] 
    for petition in petitions: petition.attorney = atty
    with open(sealing_template, "rb") as doc:
        for petition in petitions:
            if petition.petition_type == "Sealing":
                petition.set_template(doc)

    with open(expungement_template, "rb") as doc:
        for petition in petitions:
            if petition.petition_type == "Expungement":
                petition.set_template(doc)


    petition_tuples = []
    for pt in petitions:
        petition_tuples.append((pt.file_name(), pt.render()))
    pkg = Compressor(archive, petition_tuples, tempdir=tempdir)
    pkg.save()
    print ("*********************************")
    print ("****** COMPLETE *****************")
    print ("*********************************")
示例#3
0
def test_add_docket(example_docket):
    rec = CRecord(Person("dummy", "name", None))
    rec.add_docket(example_docket)
    assert len(rec.cases) == 1
    assert rec.person.first_name != "dummy"