File size: 797 Bytes
239d4ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json
import os
import shutil

BASE_PATH = os.path.expanduser("~/vitalis_core")

def get_free_space():
    usage = shutil.disk_usage(BASE_PATH)
    return usage.free

def load_identity():
    identity_path = os.path.join(BASE_PATH, "core/identity.json")
    with open(identity_path, 'r') as f:
        return json.load(f)

def store_memory(data):
    memory_path = os.path.join(BASE_PATH, "memory_store.json")
    if get_free_space() < 100 * 1024 * 1024:
        if os.path.exists(memory_path):
            with open(memory_path, 'r') as f:
                lines = f.readlines()
            if len(lines) > 1:
                with open(memory_path, 'w') as f:
                    f.writelines(lines[1:])
    with open(memory_path, 'a') as f:
        json.dump(data, f)
        f.write('\n')