コード例 #1
0
ファイル: tasks.py プロジェクト: paulyc/courtlistener
def add_or_update_case_db(self, case_id):
    """Add a case from the LASC MAP using an authenticated session object

    :param self: The celery object
    :param case_id: The case ID to download, for example, '19STCV25157;SS;CV'
    :return: None
    """
    establish_good_login(self)
    lasc = make_lasc_search()

    clean_data = {}
    try:
        clean_data = lasc.get_json_from_internal_case_id(case_id)
        logger.info("Successful Query")
    except RequestException as e:
        retries_remaining = self.max_retries - self.request.retries
        if retries_remaining == 0:
            logger.error("RequestException, unable to get case at %s", case_id)
            return
        logger.info(
            "Failed to get JSON for '%s', with RequestException: %s. "
            "%s retries remaining.",
            case_id,
            e,
            retries_remaining,
        )
        r = make_redis_interface("CACHE")
        r.delete(LASC_SESSION_COOKIE_KEY, LASC_SESSION_STATUS_KEY)
        self.retry()

    if not clean_data:
        logger.info("No information for case %s. Possibly sealed?", case_id)
        return

    ds = Docket.objects.filter(case_id=case_id)
    ds_count = ds.count()
    if ds_count == 0:
        logger.info("Adding lasc case with ID: %s", case_id)
        add_case(case_id, clean_data, lasc.case_data)
    elif ds_count == 1:
        if latest_sha(case_id=case_id) != sha1_of_json_data(lasc.case_data):
            logger.info("Updating lasc case with ID: %s", case_id)
            update_case(lasc, clean_data)
        else:
            logger.info("LASC case is already up to date: %s", case_id)
    else:
        logger.warn(
            "Issue adding or updating lasc case with ID '%s' - Too "
            "many cases in system with that ID (%s cases)",
            case_id,
            ds_count,
        )
コード例 #2
0
def save_json(data, content_obj):
    """
    Save json string to file and generate SHA1.

    :param data: JSON response cleaned
    :param content_obj: The content object associated with the JSON file in
    the DB
    :return: None
    """
    json_file = LASCJSON(content_object=content_obj)
    json_file.sha1 = sha1_of_json_data(data)
    json_file.upload_type = UPLOAD_TYPE.DOCKET
    json_file.filepath.save("lasc.json", ContentFile(data))