Ejemplo n.º 1
0
def _cron_fetch_update(lock):
    court = unicode(lock.court)
    casenum = unicode(lock.casenum)
    nonce = unicode(lock.nonce)

    docketstring, fetcherror = IADirect.get_docket_string(court, casenum)

    if not docketstring:
        # Couldn't get the docket.  Try again later.

        if nonce:
            BucketLockManager.try_lock_later(lock)
        else:
            lock.delete()
        print "  %s.%s couldn't fetch the docket: %d" % (court, casenum,
                                                         fetcherror)
        return

    ia_docket, message = DocketXML.parse_xml_string(docketstring)

    if not ia_docket:
        # Docket parsing error.

        if nonce:
            BucketLockManager.try_lock_later(lock)
        else:
            lock.delete()
        print "  %s.%s docket parsing error: %s" % (court, casenum, message)
        return
    elif ia_docket.nonce == nonce or not nonce:
        # Got the docket and it is either:
        # 1. up-to-date (nonce match), or
        #  2. expired (ignore nonce)
        # In both scenarios, update the local DB.
        DocumentManager.update_local_db(ia_docket, ignore_available=0)

        print "  %s.%s fetched and DB updated." % (court, casenum)

        ia_docket_orig_hash = hash(pickle.dumps(ia_docket))

        local_docket = DocumentManager.create_docket_from_local_documents(
            court, casenum)

        if local_docket:
            ia_docket.merge_docket(local_docket)

        ia_docket_after_local_merge_hash = hash(pickle.dumps(ia_docket))

        if ia_docket_orig_hash != ia_docket_after_local_merge_hash:
            print " After fetch, some locally stored information was " \
                  "missing from %s.%s. Local info addition scheduled." % (
                      court, casenum)
            UploadHandler.do_me_up(ia_docket)

        # Remove the lock.
        lock.delete()
    else:
        # Got the docket but it is not update to date.  Try again later.
        BucketLockManager.try_lock_later(lock)
        print "  %s.%s fetched, wait more." % (court, casenum)
Ejemplo n.º 2
0
def _cron_me_up(ia_docket, docket, ppentry):
    """ Merge and update docket"""

    ia_court = ia_docket.casemeta["court"]
    ia_casenum = ia_docket.casemeta["pacer_case_num"]

    # Save the original hash to diff with later
    ia_docket_orig_hash = hash(pickle.dumps(ia_docket))
    ia_casemeta_orig_hash = hash(pickle.dumps(ia_docket.casemeta))

    # Merge ia_docket with our local database information to fill in blank
    # fields that may exist in ia
    local_docket = DocumentManager.create_docket_from_local_documents(
        ia_court, ia_casenum, docket)

    if local_docket:
        ia_docket.merge_docket(local_docket)

    ia_docket_after_local_merge_hash = hash(pickle.dumps(ia_docket))

    if ia_docket_orig_hash != ia_docket_after_local_merge_hash:
        print " Some locally stored information was missing from %s.%s. Local info added." % (
            ia_court, ia_casenum)

    # Step 2: Merge new docket into the existing IA docket
    ia_docket.merge_docket(docket)

    # Step 3: If diff, then upload the merged docket
    ia_docket_merged_hash = hash(pickle.dumps(ia_docket))

    if ia_docket_orig_hash != ia_docket_merged_hash:

        # Generate a new nonce for the docket
        ia_docket.nonce = DocketXML.generate_new_nonce()

        ia_casemeta_merged_hash = hash(pickle.dumps(ia_docket.casemeta))
        casemeta_diff = ia_casemeta_orig_hash != ia_casemeta_merged_hash

        # Put the docket to IA
        put_result, put_msg = put_docket(ia_docket,
                                         ia_court,
                                         ia_casenum,
                                         ppentry,
                                         casemeta_diff=casemeta_diff)

        return put_result, "merged: %s" % put_msg

    else:
        # No difference between IA docket and this docket, no need to upload.

        filename = ppentry.filename

        # Delete the entry from the DB
        ppentry.delete()
        # Delete the pickle file
        delete_pickle(filename)

        # Return False to reflect "no update"
        return False, "not merged: no diff."
Ejemplo n.º 3
0
def _cron_fetch_update(lock):
    court = unicode(lock.court)
    casenum = unicode(lock.casenum)
    nonce = unicode(lock.nonce)

    docketstring, fetcherror = IADirect.get_docket_string(court, casenum)

    if not docketstring:
        # Couldn't get the docket.  Try again later.

        if nonce:
            BucketLockManager.try_lock_later(lock)
        else:
            lock.delete()
        print "  %s.%s couldn't fetch the docket: %d" % (court, casenum,
                                                         fetcherror)
        return

    ia_docket, message = DocketXML.parse_xml_string(docketstring)

    if not ia_docket:
        # Docket parsing error.

        if nonce:
            BucketLockManager.try_lock_later(lock)
        else:
            lock.delete()
        print "  %s.%s docket parsing error: %s" % (court, casenum,
                                                    message)
        return
    elif ia_docket.nonce == nonce or not nonce:
        # Got the docket and it is either:
        #  1. up-to-date (nonce match), or
        #  2. expired (ignore nonce)
        # In both scenarios, update the local DB.
        DocumentManager.update_local_db(ia_docket, ignore_available=0)

        print "  %s.%s fetched and DB updated." % (court, casenum)

        ia_docket_orig_hash = hash(pickle.dumps(ia_docket))

        local_docket = DocumentManager.create_docket_from_local_documents(court, casenum)

        if local_docket:
            ia_docket.merge_docket(local_docket)

        ia_docket_after_local_merge_hash = hash(pickle.dumps(ia_docket))

        if ia_docket_orig_hash != ia_docket_after_local_merge_hash:
            print " After fetch, some locally stored information was missing from %s.%s. Local info addition scheduled."  % (court, casenum)
            UploadHandler.do_me_up(ia_docket)

        # Remove the lock.
        lock.delete()
    else:
        # Got the docket but it is not update to date.  Try again later.
        BucketLockManager.try_lock_later(lock)
        print "  %s.%s fetched, wait more." % (court, casenum)
Ejemplo n.º 4
0
def _cron_me_up(ia_docket, docket, ppentry):
    """ Merge and update docket"""

    ia_court = ia_docket.casemeta["court"]
    ia_casenum = ia_docket.casemeta["pacer_case_num"]

    # Save the original hash to diff with later
    ia_docket_orig_hash = hash(pickle.dumps(ia_docket))
    ia_casemeta_orig_hash = hash(pickle.dumps(ia_docket.casemeta))

    # Merge ia_docket with our local database information to fill in blank
    # fields that may exist in ia
    local_docket = DocumentManager.create_docket_from_local_documents(ia_court,
                                                                      ia_casenum,
                                                                      docket)

    if local_docket:
        ia_docket.merge_docket(local_docket)

    ia_docket_after_local_merge_hash = hash(pickle.dumps(ia_docket))

    if ia_docket_orig_hash != ia_docket_after_local_merge_hash:
        print " Some locally stored information was missing from %s.%s. Local info added." % (
            ia_court, ia_casenum)

    # Step 2: Merge new docket into the existing IA docket
    ia_docket.merge_docket(docket)

    # Step 3: If diff, then upload the merged docket
    ia_docket_merged_hash = hash(pickle.dumps(ia_docket))

    if ia_docket_orig_hash != ia_docket_merged_hash:

        # Generate a new nonce for the docket
        ia_docket.nonce = DocketXML.generate_new_nonce()

        ia_casemeta_merged_hash = hash(pickle.dumps(ia_docket.casemeta))
        casemeta_diff = ia_casemeta_orig_hash != ia_casemeta_merged_hash

        # Put the docket to IA
        put_result, put_msg = put_docket(ia_docket, ia_court, ia_casenum,
                                         ppentry, casemeta_diff=casemeta_diff)

        return put_result, "merged: %s" % put_msg

    else:
        # No difference between IA docket and this docket, no need to upload.

        filename = ppentry.filename

        # Delete the entry from the DB
        ppentry.delete()
        # Delete the pickle file
        delete_pickle(filename)

        # Return False to reflect "no update"
        return False, "not merged: no diff."
        sys.stderr.write("Usage: %s <filename_containing_cases_to_repair>\n " %
                         sys.argv[0])
        sys.stderr.write(
            "      The contents of filename should have a single case per line, each identified by 'court casenum'\n "
        )
        sys.exit(1)

    cases_to_repair = read_in_cases_to_repair(sys.argv[1])

    for case in cases_to_repair:
        court = case[0]
        casenum = case[1]

        print "Repairing case %s.%s...." % (court, casenum)

        docket = DocumentManager.create_docket_from_local_documents(
            court, casenum)

        if docket:
            # this will merge our docket with existing one on IA
            UploadHandler.do_me_up(docket)
        else:
            print " Could not create docket from local documents for %s %s" % (
                court, casenum)

#  for each case, create docket fromlocal

#  call do_me_up(docket)
#  download ia_docket
#
#  merge ia docket and local docket
#
Ejemplo n.º 6
0
  '''

  if len(sys.argv) != 2:
    sys.stderr.write("Usage: %s <filename_containing_cases_to_repair>\n " % sys.argv[0])
    sys.stderr.write("      The contents of filename should have a single case per line, each identified by 'court casenum'\n " )
    sys.exit(1)

  cases_to_repair = read_in_cases_to_repair(sys.argv[1])

  for case in cases_to_repair:
    court = case[0]
    casenum = case[1]

    print "Repairing case %s.%s...." % (court, casenum)

    docket = DocumentManager.create_docket_from_local_documents(court, casenum)

    if docket:
        # this will merge our docket with existing one on IA
        UploadHandler.do_me_up(docket)
    else:
        print " Could not create docket from local documents for %s %s" % (court, casenum)



#  for each case, create docket fromlocal

#  call do_me_up(docket)
#  download ia_docket
#
#  merge ia docket and local docket