Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions scripts/python/clean_order_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

"""
Removes closed orders from the local order history file.
This helps keep JSON history files manageable.
"""

import json
import sys
from pathlib import Path

HISTORY_PATH = Path("data/order_history.json")

def main() -> None:
if not HISTORY_PATH.exists():
print(f"No history file found at {HISTORY_PATH}")
return
data = json.loads(HISTORY_PATH.read_text())
original_len = len(data.get("orders", []))
data["orders"] = [o for o in data.get("orders", []) if o.get("status") != "closed"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script adds "orders" key to files lacking it

The code unconditionally assigns data["orders"] even when the original JSON file doesn't contain an "orders" key. If run on a file without this key, the script will add "orders": [] to the file structure rather than leaving it unchanged. A cleanup utility probably shouldn't modify files that have no matching data to clean. The logic uses data.get("orders", []) to safely read, but then always writes back via assignment.

Fix in Cursor Fix in Web

with open(HISTORY_PATH, "w") as f:
json.dump(data, f, indent=2)
print(f"Cleaned order history: {original_len} → {len(data['orders'])} active orders")

if __name__ == "__main__":
main()