Save a single result to the results file.
(filename: str, result: Dict)
| 590 | } |
| 591 | |
| 592 | def save_result(filename: str, result: Dict): |
| 593 | """Save a single result to the results file.""" |
| 594 | results = [] |
| 595 | if os.path.exists(filename): |
| 596 | try: |
| 597 | with open(filename, 'r') as f: |
| 598 | results = json.load(f) |
| 599 | except (FileNotFoundError, json.JSONDecodeError): |
| 600 | results = [] |
| 601 | |
| 602 | results.append(result) |
| 603 | |
| 604 | with open(filename, 'w') as f: |
| 605 | json.dump(results, f, indent=2) |
| 606 | |
| 607 | def load_existing_results(filename: str) -> List[Dict]: |
| 608 | """Load existing results from file if it exists.""" |