Exemplo n.º 1
0
def make_lasc_search():
    """Create a logged-in LASCSearch object with cookies pulled from cache

    :return: LASCSearch object
    """
    r = make_redis_interface('CACHE')
    session = LASCSession()
    session.cookies = pickle.loads(r.get(LASC_SESSION_COOKIE_KEY))
    return LASCSearch(session)
Exemplo n.º 2
0
    def run_parsers_on_path(self, path):
        """Test all the parsers on a given local path

        :param path: The path where you can find the files
        """
        file_paths = glob.glob(path)
        file_paths.sort()
        path_max_len = max(len(path) for path in file_paths) + 2
        for i, path in enumerate(file_paths):
            sys.stdout.write("%s. Doing %s" % (i, path.ljust(path_max_len)))
            t1 = time.time()
            dirname, filename = os.path.split(path)
            filename_sans_ext = filename.split(".")[0]
            json_path = os.path.join(
                dirname, "%s_result.json" % filename_sans_ext
            )

            lasc = LASCSearch(session=None)
            with open(path, "rb") as f:
                data = json.load(f)
                clean_data = lasc._parse_case_data(data)

            if not os.path.isfile(json_path):
                # First time testing this docket
                bar = "*" * 50
                print(
                    "\n\n%s\nJSON FILE DID NOT EXIST. CREATING IT AT:"
                    "\n\n  %s\n\n"
                    "Please test the data in this file before assuming "
                    "everything worked.\n%s\n" % (bar, json_path, bar)
                )
                with open(json_path, "w") as f:
                    json.dump(clean_data, f, indent=2, sort_keys=True)
                    continue

            with open(json_path) as f:
                j = json.load(f)
                self.assertEqual(j, clean_data)

            t2 = time.time()
            duration = t2 - t1
            warn_or_crash_slow_parser(duration, max_duration=1)
            sys.stdout.write("✓ - %0.1fs\n" % (t2 - t1))
Exemplo n.º 3
0
def add_case_from_filepath(filepath):
    """Add case to database from filepath

    :param self: The celery object
    :param filepath: Filepath string to where the item is stored
    :return: None
    """
    query = LASCSearch(None)
    with open(filepath, 'r') as f:
        original_data = f.read()

    case_data = query._parse_case_data(json.loads(original_data))
    case_id = make_case_id(case_data)

    ds = Docket.objects.filter(case_id=case_id)

    if ds.count() == 0:
        add_case(case_id, case_data, original_data)
    elif ds.count() == 1:
        logger.warn("LASC case on file system at '%s' is already in "
                    "the database ", filepath)