Exemplo n.º 1
0
def get_pacer_case_id_for_idb_row(self, pk, session):
    """Populate the pacer_case_id field in the FJC IDB table for an item in the
    IDB table
    """
    logger.info("Getting pacer_case_id for IDB item with pk %s" % pk)
    item = FjcIntegratedDatabase.objects.get(pk=pk)
    pcn = PossibleCaseNumberApi(map_cl_to_pacer_id(item.district_id), session)
    pcn.query(item.docket_number)
    params = {
        'office_number': item.office if item.office else None,
    }
    if item.plaintiff or item.defendant:
        params['case_name'] = '%s v. %s' % (item.plaintiff, item.defendant)
    if item.dataset_source in [CR_2017, CR_OLD]:
        if item.multidistrict_litigation_docket_number:
            params['docket_number_letters'] = 'md'
        else:
            params['docket_number_letters'] = 'cr'
    elif item.dataset_source in [CV_2017, CV_OLD]:
        params['docket_number_letters'] = 'cv'
    try:
        d = pcn.data(**params)
    except ParsingException:
        # Hack. Storing the error in here will bite us later.
        item.pacer_case_id = "Error"
    else:
        if d is not None:
            item.pacer_case_id = d['pacer_case_id']
            item.case_name = d['title']
    item.save()
Exemplo n.º 2
0
def get_pacer_case_id_and_title(self, docket_number, court_id, cookies,
                                case_name=None, office_number=None,
                                docket_number_letters=None, ):
    """Get the pacer_case_id and title values for a district court docket. Use
    heuristics to disambiguate the results.

    office_number and docket_number_letters are only needed when they are not
    already part of the docket_number passed in. Multiple parameters are needed
    here to allow flexibility when using this API. Some sources, like the IDB,
    have this data all separated out, so it helps not to try to recreate docket
    numbers from data that comes all pulled apart.

    :param docket_number: The docket number to look up. This is a flexible
    field that accepts a variety of docket number styles.
    :param court_id: The CourtListener court ID for the docket number
    :param cookies: A requests.cookies.RequestsCookieJar with the cookies of a
    logged-in PACER user.
    :param case_name: The case name to use for disambiguation
    :param office_number: The number (or letter) where the case took place.
    Typically, this is in the beginning of the docket number before the colon.
    This will be used for disambiguation. If you passed it as part of the
    docket number, it is not needed here.
    :param docket_number_letters: These are the letters, (cv, cr, md, etc.)
    that may appear in a docket number. This is used for disambiguation. If
    you passed these letters in the docket number, you do not need to pass
    these letters again here.
    :return: The dict formed by the PossibleCaseNumberApi lookup if a good
    value is identified, else None. The dict takes the form of:
        {
            u'docket_number': force_unicode(node.xpath('./@number')[0]),
            u'pacer_case_id': force_unicode(node.xpath('./@id')[0]),
            u'title': force_unicode(node.xpath('./@title')[0]),
        }
    """
    logger.info("Getting pacer_case_id for docket_number %s in court %s",
                docket_number, court_id)
    s = PacerSession(cookies=cookies)
    report = PossibleCaseNumberApi(map_cl_to_pacer_id(court_id), s)
    try:
        report.query(docket_number)
    except requests.RequestException as exc:
        logger.warning("RequestException while running possible case number "
                       "query. Trying again if retries not exceeded: %s.%s",
                       court_id, docket_number)
        if self.request.retries == self.max_retries:
            self.request.callbacks = None
            return None
        raise self.retry(exc=exc)

    try:
        return report.data(case_name=case_name, office_number=office_number,
                           docket_number_letters=docket_number_letters)
    except ParsingException:
        return None
Exemplo n.º 3
0
def get_pacer_case_id_for_idb_row(self, pk, session):
    """Populate the pacer_case_id field for an item in the IDB table"""
    logger.info("Getting pacer_case_id for IDB item with pk %s" % pk)
    item = FjcIntegratedDatabase.objects.get(pk=pk)
    pcn = PossibleCaseNumberApi(map_cl_to_pacer_id(item.district_id), session)
    pcn.query(item.docket_number)
    d = pcn.data(case_name='%s v. %s' % (item.plaintiff, item.defendant))
    if d is not None:
        item.pacer_case_id = d['pacer_case_id']
        item.case_name = d['title']
    else:
        # Hack. Storing the error in here will bite us later.
        item.pacer_case_id = "Error"
    item.save()
Exemplo n.º 4
0
def fetch_pacer_case_id_and_title(s, fq, court_id):
    """Use PACER's hidden API to learn the pacer_case_id of a case

    :param s: A PacerSession object to use
    :param fq: The PacerFetchQueue object to use
    :param court_id: The CL ID of the court
    :return: A dict of the new information or an empty dict if it fails
    """
    if (fq.docket_id and not fq.docket.pacer_case_id) or fq.docket_number:
        # We lack the pacer_case_id either on the docket or from the
        # submission. Look it up.
        docket_number = fq.docket_number or getattr(fq.docket, "docket_number",
                                                    None)
        report = PossibleCaseNumberApi(map_cl_to_pacer_id(court_id), s)
        report.query(docket_number)
        return report.data()
    return {}
Exemplo n.º 5
0
    def get_pacer_case_ids(self):
        """Find PACER Case IDs from iQuery

        :return: None
        """

        q = Query()
        db = TinyDB("db/master.json")
        fjc_table = db.table("fjc")
        for row in fjc_table.search((q.PACER_CASE_ID == "")):
            report = PossibleCaseNumberApi(row["COURT"], self.s)
            report.query(row["DOCKET_NO"])
            data = report.data(office_number=row["OFFICE"], docket_number_letters="cv")
            fjc_table.update(
                {"PACER_CASE_ID": data["pacer_case_id"], "TITLE": data["title"]},
                doc_ids=[row.doc_id],
            )