Refactor retailer collection entrypoints
This commit is contained in:
@@ -648,6 +648,27 @@ def main(
|
||||
window_days,
|
||||
months_back,
|
||||
firefox_profile_dir,
|
||||
):
|
||||
click.echo("legacy entrypoint: prefer collect_costco_web.py for data-model outputs")
|
||||
run_collection(
|
||||
outdir=outdir,
|
||||
document_type=document_type,
|
||||
document_sub_type=document_sub_type,
|
||||
window_days=window_days,
|
||||
months_back=months_back,
|
||||
firefox_profile_dir=firefox_profile_dir,
|
||||
)
|
||||
|
||||
|
||||
def run_collection(
|
||||
outdir,
|
||||
document_type,
|
||||
document_sub_type,
|
||||
window_days,
|
||||
months_back,
|
||||
firefox_profile_dir,
|
||||
orders_filename="orders.csv",
|
||||
items_filename="items.csv",
|
||||
):
|
||||
outdir = Path(outdir)
|
||||
raw_dir = outdir / "raw"
|
||||
@@ -706,8 +727,8 @@ def main(
|
||||
write_json(raw_dir / f"{safe_filename(receipt_id)}.json", detail_payload)
|
||||
|
||||
orders, items = flatten_costco_data(summary_payload, detail_payloads, raw_dir)
|
||||
write_csv(outdir / "orders.csv", orders, ORDER_FIELDS)
|
||||
write_csv(outdir / "items.csv", items, ITEM_FIELDS)
|
||||
write_csv(outdir / orders_filename, orders, ORDER_FIELDS)
|
||||
write_csv(outdir / items_filename, items, ITEM_FIELDS)
|
||||
click.echo(f"wrote {len(orders)} orders and {len(items)} item rows to {outdir}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user