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