Exemple #1
0
 def create(info,
            case_number,
            citation_number,
            date_location,
            type_status,
            case_detail_link,
            balance="0") -> CaseSummary:
     name = info[0]
     birth_year = CaseSummary._parse_birth_year(info)
     citation_number = citation_number[0] if citation_number else ""
     date, location = date_location
     date = date_class.fromdatetime(datetime.strptime(date, "%m/%d/%Y"))
     violation_type, current_status = type_status
     balance_due_in_cents = CaseCreator.compute_balance_due_in_cents(
         balance)
     return CaseSummary(
         name,
         birth_year,
         case_number,
         citation_number,
         location,
         date,
         violation_type,
         current_status,
         case_detail_link,
         balance_due_in_cents,
     )
 def _build_disposition(case_parser_data, charge_id):
     disposition_data = case_parser_data.hashed_dispo_data.get(charge_id)
     if disposition_data:
         date = date_class.fromdatetime(
             datetime.strptime(disposition_data.get("date"), "%m/%d/%Y")
         )  # TODO: Log error if format is not correct
         ruling = disposition_data.get("ruling")
         disposition = DispositionCreator.create(date, ruling, "amended" in disposition_data["event"].lower())
     else:
         disposition = DispositionCreator.create(date_class.today(), "missing")
     return disposition
Exemple #3
0
 def _parse_charge_edits(charge_edits):
     charge_dict: Dict[str, Any] = {}
     for key, value in charge_edits.items():
         if key == "disposition":
             disposition = value
             if disposition:
                 charge_dict["disposition"] = DispositionCreator.create(
                     date_class.fromdatetime(
                         datetime.strptime(disposition["date"],
                                           "%m/%d/%Y")),
                     disposition["ruling"],
                 )
             else:
                 charge_dict["disposition"] = None
         elif key in ("date", "probation_revoked"):
             if value:
                 charge_dict[key] = date_class.fromdatetime(
                     datetime.strptime(value, "%m/%d/%Y"))
         else:
             charge_dict[key] = value
     return charge_dict
 def _build_oeci_charge(
     charge_id, ambiguous_charge_id, charge_dict, case_parser_data, balance_due_in_cents
 ) -> OeciCharge:
     probation_revoked = case_parser_data.probation_revoked
     charge_dict["date"] = date_class.fromdatetime(datetime.strptime(charge_dict["date"], "%m/%d/%Y"))
     disposition = Crawler._build_disposition(case_parser_data, charge_id)
     return OeciCharge(
         ambiguous_charge_id,
         disposition=disposition,
         probation_revoked=probation_revoked,
         balance_due_in_cents=balance_due_in_cents,
         edit_status=EditStatus.UNCHANGED,
         **charge_dict,
     )
 def feed(data) -> CaseParserData:
     soup = BeautifulSoup(data, "html.parser")
     hashed_charge_data = CaseParser.__build_charge_table_data(soup)
     (
         hashed_dispo_data,
         probation_revoked_date_string,
     ) = CaseParser.__build_hashed_dispo_data_and_probation_revoked(soup)
     balance_due = CaseParser.__build_balance_due(soup)
     if probation_revoked_date_string:
         probation_revoked = date.fromdatetime(
             datetime.strptime(probation_revoked_date_string, "%m/%d/%Y"))
     else:
         probation_revoked = None  # type: ignore
     return CaseParserData(hashed_charge_data, hashed_dispo_data,
                           balance_due, probation_revoked)
Exemple #6
0
class RecordEditor:
    @staticmethod
    def edit_search_results(search_result_cases: List[OeciCase],
                            edits) -> Tuple[List[OeciCase], List[Charge]]:
        edited_cases: List[OeciCase] = []
        new_charges_acc: List[Charge] = []
        for case in search_result_cases:
            case_number = case.summary.case_number
            if case_number in edits.keys():
                if edits[case_number]["action"] == "edit":
                    edited_case, new_charges = RecordEditor._edit_case(
                        case, edits[case_number])
                    edited_cases.append(edited_case)
                    new_charges_acc += new_charges
                # else: if the action name for this case_number isn't "edit", assume it is "delete" and skip it
            else:
                edited_cases.append(case)
        return edited_cases, new_charges_acc

    @staticmethod
    def _edit_case(case: OeciCase,
                   case_edits) -> Tuple[OeciCase, List[Charge]]:
        if "summary" in case_edits.keys():
            case_summary_edits: Dict[str, Any] = {}
            for key, value in case_edits["summary"].items():
                if key == "date":
                    case_summary_edits["date"] = date_class.fromdatetime(
                        datetime.strptime(value, "%m/%d/%Y"))
                elif key == "balance_due":
                    case_summary_edits[
                        "balance_due_in_cents"] = CaseCreator.compute_balance_due_in_cents(
                            value)
                elif key == "birth_year":
                    case_summary_edits["birth_year"] = int(value)
                else:
                    case_summary_edits[key] = value
            edited_summary = replace(case.summary, **case_summary_edits)
        else:
            edited_summary = case.summary
        new_charges: List[Charge] = []
        if "charges" in case_edits.keys():
            edited_charges, new_charges = RecordEditor._edit_charges(
                case.summary.case_number, case.charges, case_edits["charges"])
        else:
            edited_charges = case.charges
        return OeciCase(edited_summary, edited_charges), new_charges
Exemple #7
0
 def _build_today(today_string: str) -> date_class:
     try:
         today_datetime = datetime.strptime(today_string, "%m/%d/%Y")
         return date_class.fromdatetime(today_datetime)
     except:
         return date_class.today()
Exemple #8
0
                raise ValueError(
                    f"Unknown edit status for case {case.summary.case_number}")
            edited_case, new_charges = RecordEditor._edit_case(case, edit)
            edited_cases.append(edited_case)
            new_charges_accumulator += new_charges
        return edited_cases, new_charges_accumulator

    @staticmethod
    def _edit_case(case: OeciCase,
                   case_edits) -> Tuple[OeciCase, List[Charge]]:
        case_summary_edits: Dict[str, Any] = {}
        for key, value in case_edits["summary"].items():
            if key == "edit_status":
                case_summary_edits["edit_status"] = EditStatus(value)
            if key == "date":
                case_summary_edits["date"] = date_class.fromdatetime(
                    datetime.strptime(value, "%m/%d/%Y"))
            elif key == "balance_due":
                case_summary_edits[
                    "balance_due_in_cents"] = CaseCreator.compute_balance_due_in_cents(
                        value)
            elif key == "birth_year":
                case_summary_edits["birth_year"] = int(value)
            else:
                case_summary_edits[key] = value
        edited_summary = replace(case.summary, **case_summary_edits)
        new_charges: List[Charge] = []
        if case_summary_edits["edit_status"] == EditStatus.DELETE:
            edited_charges = RecordEditor._mark_charges_as_deleted(
                case.charges)
        elif "charges" in case_edits.keys():
            edited_charges, new_charges = RecordEditor._edit_charges(