| 75 | |
| 76 | |
| 77 | def load(path=JSON_PATH): |
| 78 | records = {} |
| 79 | with open(path) as fp: |
| 80 | raw_data = json.load(fp) |
| 81 | for collection, raw_records in raw_data['Schedule'].items(): |
| 82 | record_type = collection[:-1] |
| 83 | cls_name = record_type.capitalize() |
| 84 | cls = globals().get(cls_name, Record) |
| 85 | if inspect.isclass(cls) and issubclass(cls, Record): |
| 86 | factory = cls |
| 87 | else: |
| 88 | factory = Record |
| 89 | for raw_record in raw_records: |
| 90 | key = f'{record_type}.{raw_record["serial"]}' |
| 91 | records[key] = factory(**raw_record) |
| 92 | return records |