From 99973a8bc161639c40a4261c7351de9a628903b4 Mon Sep 17 00:00:00 2001 From: Derek Herincx Date: Thu, 22 Aug 2024 11:08:03 -0400 Subject: [PATCH] Update CLI parser to support updated logic for restructured asyncio coroutines in parser --- README.md | 6 +++++- src/fpds/cli/parse.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 415a9e5..9975bbe 100644 --- a/README.md +++ b/README.md @@ -51,13 +51,17 @@ $ fpds parse "LAST_MOD_DATE=[2022/01/01, 2022/05/01]" "AGENCY_CODE=7504" -o my- Same request via python interpreter: ``` import asyncio +from itertools import chain from fpds import fpdsRequest request = fpdsRequest( LAST_MOD_DATE="[2022/01/01, 2022/05/01]", AGENCY_CODE="7504" ) -data = list(asyncio.run(request.data())) + +# results are nested lists so de-nest +data = asyncio.run(request.data()) +records = list(chain.from_iterable(data)) ``` For linting and formatting, we use `flake8` and `black`. diff --git a/src/fpds/cli/parse.py b/src/fpds/cli/parse.py index 96d1969..18bc930 100644 --- a/src/fpds/cli/parse.py +++ b/src/fpds/cli/parse.py @@ -6,7 +6,9 @@ last_updated: 12/30/2022 """ +import asyncio import json +from itertools import chain from pathlib import Path from uuid import uuid4 @@ -65,7 +67,9 @@ def parse(params, output): request = fpdsRequest(**params_kwargs, cli_run=True) click.echo("Retrieving FPDS records from ATOM feed...") - records = request() + + data = asyncio.run(request.data()) + records = list(chain.from_iterable(data)) DATA_DIR = OUTPUT_PATH if output else FPDS_DATA_DATE_DIR DATA_FILE = DATA_DIR / f"{uuid4()}.json"