File size: 716 Bytes
29cdc9d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import json, time, os
class MemoryBank:
def __init__(self, storage_path="vitalis_memory.json"):
self.storage_path = os.path.abspath(storage_path)
def record_event(self, event_type, data):
memory = {}
if os.path.exists(self.storage_path):
try:
with open(self.storage_path, 'r') as f:
memory = json.load(f)
except json.JSONDecodeError:
pass # Ignore corruption, overwrite with new memory
timestamp = str(time.time())
memory[timestamp] = {"type": event_type, "payload": data}
with open(self.storage_path, 'w') as f:
json.dump(memory, f, indent=2)
|