def import_resource_org_item(case_location): """Using the path to a case, import it, gathering all needed meta data. Path is any valid URI that the requests library can handle. """ def get_file(location): if location.startswith('/'): with open(location) as f: r = requests.Session() r.content = f.read() else: r = requests.get(location) return fromstring(r.content), get_clean_body_content(r.content) # Get trees and text for the opinion itself and for the index page # that links to it. Each has useful data. case_tree, case_text = get_file(case_location) vol_location = case_location.rsplit('/', 1)[-2] + '/index.html' vol_tree, vol_text = get_file(vol_location) html, blocked = anonymize(get_case_body(case_tree)) case_location_relative = case_location.rsplit('/', 1)[1] case_name, status = get_case_name_and_status(vol_tree, case_location_relative) docket = Docket( docket_number=get_docket_number(case_location), court=Court.objects.get(pk=get_court_id(case_tree)), case_name=case_name, ) doc = Document( case_name=case_name, federal_cite_one=get_west_cite(vol_tree, case_location_relative), date_filed=get_date_filed(vol_tree, case_location_relative), source='R', sha1=hashlib.sha1(case_text).hexdigest(), docket=docket, download_url=case_location, html=html, precedential_status=status, ) if blocked: doc.blocked = True docket.blocked = True doc.date_blocked = datetime.date.today() docket.date_blocked = datetime.date.today() docket.save() doc.docket = docket doc.save() # Update the citation graph from cl.citations.tasks import update_document_by_id update_document_by_id(doc.pk) return doc
def import_resource_org_item(case_location): """Using the path to a case, import it, gathering all needed meta data. Path is any valid URI that the requests library can handle. """ def get_file(location): if location.startswith('/'): with open(location) as f: r = requests.Session() r.content = f.read() else: r = requests.get(location) return fromstring(r.content), get_clean_body_content(r.content) # Get trees and text for the opinion itself and for the index page # that links to it. Each has useful data. case_tree, case_text = get_file(case_location) vol_location = case_location.rsplit('/', 1)[-2] + '/index.html' vol_tree, vol_text = get_file(vol_location) html, blocked = anonymize(get_case_body(case_tree)) case_location_relative = case_location.rsplit('/', 1)[1] case_name, status = get_case_name_and_status( vol_tree, case_location_relative) docket = Docket( docket_number=get_docket_number(case_location), court=Court.objects.get(pk=get_court_id(case_tree)), case_name=case_name, ) doc = Document( case_name=case_name, federal_cite_one=get_west_cite(vol_tree, case_location_relative), date_filed=get_date_filed(vol_tree, case_location_relative), source='R', sha1=hashlib.sha1(case_text).hexdigest(), docket=docket, download_url=case_location, html=html, precedential_status=status, ) if blocked: doc.blocked = True docket.blocked = True doc.date_blocked = datetime.date.today() docket.date_blocked = datetime.date.today() docket.save() doc.docket = docket doc.save() # Update the citation graph from cl.citations.tasks import update_document_by_id update_document_by_id(doc.pk) return doc
def test_auto_blocking_small_bankr_docket(self): """Do we properly set small bankruptcy dockets to private?""" d = Docket() d.court = Court.objects.get(pk='akb') blocked, date_blocked = get_blocked_status(d) self.assertTrue(blocked, msg="Bankruptcy dockets with few entries " "should be blocked.") blocked, date_blocked = get_blocked_status(d, count_override=501) self.assertFalse(blocked, msg="Bankruptcy dockets with many entries " "should not be blocked") # This should stay blocked even though it's a big bankruptcy docket. d.blocked = True blocked, date_blocked = get_blocked_status(d, count_override=501) self.assertTrue(blocked, msg="Bankruptcy dockets that start blocked " "should stay blocked.")
def update_docket_metadata(d: Docket, docket_data: Dict[str, Any]) -> Docket: """Update the Docket object with the data from Juriscraper. Works on either docket history report or docket report (appellate or district) results. """ d = update_case_names(d, docket_data["case_name"]) mark_ia_upload_needed(d, save_docket=False) d.docket_number = docket_data["docket_number"] or d.docket_number d.date_filed = docket_data.get("date_filed") or d.date_filed d.date_last_filing = ( docket_data.get("date_last_filing") or d.date_last_filing ) d.date_terminated = docket_data.get("date_terminated") or d.date_terminated d.cause = docket_data.get("cause") or d.cause d.nature_of_suit = docket_data.get("nature_of_suit") or d.nature_of_suit d.jury_demand = docket_data.get("jury_demand") or d.jury_demand d.jurisdiction_type = ( docket_data.get("jurisdiction") or d.jurisdiction_type ) d.mdl_status = docket_data.get("mdl_status") or d.mdl_status judges = get_candidate_judges( docket_data.get("assigned_to_str"), d.court_id, docket_data.get("date_filed"), ) if judges is not None and len(judges) == 1: d.assigned_to = judges[0] d.assigned_to_str = docket_data.get("assigned_to_str") or "" judges = get_candidate_judges( docket_data.get("referred_to_str"), d.court_id, docket_data.get("date_filed"), ) if judges is not None and len(judges) == 1: d.referred_to = judges[0] d.referred_to_str = docket_data.get("referred_to_str") or "" d.blocked, d.date_blocked = get_blocked_status(d) return d