def update_docket_metadata(d, docket_data): """Update the Docket object with the data from Juriscraper""" d.docket_number = d.docket_number or docket_data['docket_number'] d.pacer_case_id = d.pacer_case_id or docket_data['pacer_case_id'] d.date_filed = d.date_filed or docket_data['date_filed'] d.date_terminated = d.date_terminated or docket_data['date_terminated'] d.case_name = d.case_name or docket_data['case_name'] d.case_name_short = d.case_name_short or cnt.make_case_name_short( d.case_name) d.cause = d.cause or docket_data['cause'] d.nature_of_suit = d.nature_of_suit or docket_data['nature_of_suit'] d.jury_demand = d.jury_demand or docket_data['jury_demand'] d.jurisdiction_type = d.jurisdiction_type or docket_data['jurisdiction'] judges = get_candidate_judges(docket_data.get('assigned_to_str'), d.court_id, docket_data['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['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
def update_docket_metadata(d, docket_data): """Update the Docket object with the data from Juriscraper. Works on either docket history report or docket report results. """ d.docket_number = docket_data['docket_number'] or d.docket_number d.date_filed = docket_data['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['date_terminated'] or d.date_terminated if d.case_name == "Unknown Case Title" or not d.case_name: d.case_name = docket_data['case_name'] or d.case_name d.case_name_short = cnt.make_case_name_short(d.case_name) or d.case_name_short 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 judges = get_candidate_judges(docket_data.get('assigned_to_str'), d.court_id, docket_data['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['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
def update_docket_metadata(d, docket_data): """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) d.docket_number = docket_data['docket_number'] or d.docket_number d.date_filed = docket_data['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['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['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
def save_everything(self, items, index=False, backscrape=False): """Saves all the sub items and associates them as appropriate. """ docket, cluster = items['docket'], items['cluster'] opinion, citations = items['opinion'], items['citations'] docket.save() cluster.docket = docket cluster.save(index=False) # Index only when the opinion is associated. for citation in citations: citation.cluster_id = cluster.pk citation.save() if cluster.judges: candidate_judges = get_candidate_judges( cluster.judges, docket.court.pk, cluster.date_filed, ) if len(candidate_judges) == 1: opinion.author = candidate_judges[0] if len(candidate_judges) > 1: for candidate in candidate_judges: cluster.panel.add(candidate) opinion.cluster = cluster opinion.save(index=index) if not backscrape: RealTimeQueue.objects.create(item_type='o', item_pk=opinion.pk)
def save_everything( items: Dict[str, Any], index: bool = False, backscrape: bool = False, ) -> None: """Saves all the sub items and associates them as appropriate.""" docket, cluster = items["docket"], items["cluster"] opinion, citations = items["opinion"], items["citations"] docket.save() cluster.docket = docket cluster.save(index=False) # Index only when the opinion is associated. for citation in citations: citation.cluster_id = cluster.pk citation.save() if cluster.judges: candidate_judges = get_candidate_judges(cluster.judges, docket.court.pk, cluster.date_filed) if len(candidate_judges) == 1: opinion.author = candidate_judges[0] if len(candidate_judges) > 1: for candidate in candidate_judges: cluster.panel.add(candidate) opinion.cluster = cluster opinion.save(index=index) if not backscrape: RealTimeQueue.objects.create(item_type=SEARCH_TYPES.OPINION, item_pk=opinion.pk)
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
def assign_authors_to_oral_arguments(testing=False): afs = (Audio.objects.exclude(judges='') .select_related('docket__court__id', 'docket__date_argued') .only('docket__date_argued', 'judges', 'docket__court_id')) for af in afs: judge_str = unidecode(af.judges) print " Judge string: %s" % judge_str candidates = get_candidate_judges(judge_str, af.docket.court_id, af.docket.date_argued) for candidate in candidates: if not testing: af.panel.add(candidate)
def assign_authors_to_opinions(jurisdictions=None, testing=False): clusters = (OpinionCluster.objects.exclude( judges="").select_related("docket__court__id").only( "date_filed", "judges", "docket__court_id")) if jurisdictions is not None: clusters = clusters.filter( docket__court__jurisdiction__in=jurisdictions) total = clusters.count() i = 0 for cluster in clusters: i += 1 print u"(%s/%s): Processing: %s, %s" % ( i, total, cluster.pk, cluster.date_filed, ) judge_str = unidecode(cluster.judges) print " Judge string: %s" % judge_str if "curiam" in judge_str.lower(): opinion = cluster.sub_opinions.all()[0] opinion.per_curiam = True print u" Per Curiam assigned." if not testing: opinion.save(index=False) continue candidates = get_candidate_judges(judge_str, cluster.docket.court_id, cluster.date_filed) if len(candidates) < 1: # No DB matches print u" No match." elif len(candidates) == 1: # only one candidate, assign author opinion = cluster.sub_opinions.all()[0] opinion.author = candidates[0] print u" Author assigned: %s" % unidecode(str(candidates[0])) if not testing: opinion.save(index=False) elif len(candidates) > 1: # more than one DB match, assign panel print u" Panel assigned: %s" % candidates if not testing: for candidate in candidates: cluster.panel.add(candidate)
def get_judges(self, node): """Parse out the judge string and then look it up in the DB""" try: s = self.case_details.xpath('%s/text()' % node)[0].strip() except IndexError: logger.info("Couldn't get judge for node: %s" % node) return None, '' else: judges = get_candidate_judges(s, self.court.pk, self.date_filed) if len(judges) == 0: return None, s elif len(judges) == 1: return judges[0], s else: return None, s
def update_docket_metadata(d, docket_data): """Update the Docket object with the data from Juriscraper""" d.docket_number = d.docket_number or docket_data['docket_number'] d.pacer_case_id = d.pacer_case_id or docket_data['pacer_case_id'] d.date_filed = d.date_filed or docket_data['date_filed'] d.date_terminated = d.date_terminated or docket_data['date_terminated'] d.case_name = d.case_name or docket_data['case_name'] d.case_name_short = d.case_name_short or cnt.make_case_name_short(d.case_name) d.cause = d.cause or docket_data['cause'] d.nature_of_suit = d.nature_of_suit or docket_data['nature_of_suit'] d.jury_demand = d.jury_demand or docket_data['jury_demand'] d.jurisdiction_type = d.jurisdiction_type or docket_data['jurisdiction'] judges = get_candidate_judges(docket_data.get('assigned_to_str'), d.court_id, docket_data['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['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
def assign_authors_to_opinions(jurisdictions=None, testing=False): clusters = (OpinionCluster.objects .exclude(judges='') .select_related('docket__court__id') .only('date_filed', 'judges', 'docket__court_id')) if jurisdictions is not None: clusters = clusters.filter( docket__court__jurisdiction__in=jurisdictions) total = clusters.count() i = 0 for cluster in clusters: i += 1 print u"(%s/%s): Processing: %s, %s" % (i, total, cluster.pk, cluster.date_filed) judge_str = unidecode(cluster.judges) print " Judge string: %s" % judge_str if 'curiam' in judge_str.lower(): opinion = cluster.sub_opinions.all()[0] opinion.per_curiam = True print u' Per Curiam assigned.' if not testing: opinion.save(index=False) continue candidates = get_candidate_judges(judge_str, cluster.docket.court_id, cluster.date_filed) if len(candidates) < 1: # No DB matches print u' No match.' elif len(candidates) == 1: # only one candidate, assign author opinion = cluster.sub_opinions.all()[0] opinion.author = candidates[0] print u' Author assigned: %s' % unidecode(str(candidates[0])) if not testing: opinion.save(index=False) elif len(candidates) > 1: # more than one DB match, assign panel print u' Panel assigned: %s' % candidates if not testing: for candidate in candidates: cluster.panel.add(candidate)
def save_everything(items, index=False, backscrape=False): docket, af = items["docket"], items["audio_file"] docket.save() af.docket = docket af.save(index=index) candidate_judges = [] if af.docket.court_id != "scotus": if af.judges: candidate_judges = get_candidate_judges(af.judges, docket.court.pk, af.docket.date_argued) else: candidate_judges = get_scotus_judges(af.docket.date_argued) for candidate in candidate_judges: af.panel.add(candidate) if not backscrape: RealTimeQueue.objects.create(item_type=SEARCH_TYPES.ORAL_ARGUMENT, item_pk=af.pk)
def save_everything(self, items, index=False, backscrape=False): docket, af = items['docket'], items['audio_file'] docket.save() af.docket = docket af.save(index=index) candidate_judges = [] if af.docket.court_id != 'scotus': if af.judges: candidate_judges = get_candidate_judges( af.judges, docket.court.pk, af.docket.date_argued, ) else: candidate_judges = get_scotus_judges(af.docket.date_argued) for candidate in candidate_judges: af.panel.add(candidate) if not backscrape: RealTimeQueue.objects.create(item_type='oa', item_pk=af.pk)
def update_docket_appellate_metadata(d, docket_data): """Update the metadata specific to appellate cases.""" if not any([ docket_data.get('originating_court_information'), docket_data.get('appeal_from'), docket_data.get('panel') ]): # Probably not appellate. return d, None d.panel_str = ', '.join(docket_data.get('panel', [])) or d.panel_str d.appellate_fee_status = docket_data.get('fee_status', '') or d.appellate_fee_status d.appellate_case_type_information = docket_data.get( 'case_type_information', '') or d.appellate_case_type_information d.appeal_from_str = docket_data.get('appeal_from', '') or d.appeal_from_str # Do originating court information dict og_info = docket_data.get('originating_court_information') if not og_info: return d, None if og_info.get('court_id'): cl_id = map_pacer_to_cl_id(og_info['court_id']) if Court.objects.filter(pk=cl_id).exists(): # Ensure the court exists. Sometimes PACER does weird things, # like in 14-1743 in CA3, where it says the court_id is 'uspci'. # If we don't do this check, the court ID could be invalid, and # our whole save of the docket fails. d.appeal_from_id = cl_id if d.originating_court_information: d_og_info = d.originating_court_information else: d_og_info = OriginatingCourtInformation() # Ensure we don't share A-Numbers, which can sometimes be in the docket # number field. docket_number = og_info.get('docket_number', '') or d_og_info.docket_number docket_number, _ = anonymize(docket_number) d_og_info.docket_number = docket_number d_og_info.court_reporter = og_info.get('court_reporter', '') or d_og_info.court_reporter d_og_info.date_disposed = og_info.get( 'date_disposed') or d_og_info.date_disposed d_og_info.date_filed = og_info.get('date_filed') or d_og_info.date_filed d_og_info.date_judgment = og_info.get( 'date_judgment') or d_og_info.date_judgment d_og_info.date_judgment_eod = og_info.get( 'date_judgment_eod') or d_og_info.date_judgment_eod d_og_info.date_filed_noa = og_info.get( 'date_filed_noa') or d_og_info.date_filed_noa d_og_info.date_received_coa = og_info.get( 'date_received_coa') or d_og_info.date_received_coa d_og_info.assigned_to_str = og_info.get( 'assigned_to') or d_og_info.assigned_to_str d_og_info.ordering_judge_str = og_info.get( 'ordering_judge') or d_og_info.ordering_judge_str if not all([d.appeal_from_id, d_og_info.date_filed]): # Can't do judge lookups. Call it quits. return d, d_og_info if og_info.get('assigned_to'): judges = get_candidate_judges(og_info['assigned_to'], d.appeal_from_id, d_og_info.date_filed) if judges is not None and len(judges) == 1: d_og_info.assigned_to = judges[0] if og_info.get('ordering_judge'): judges = get_candidate_judges(og_info['ordering_judge'], d.appeal_from_id, d_og_info.date_filed) if judges is not None and len(judges) == 1: d_og_info.ordering_judge = judges[0] return d, d_og_info