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