| import json, os | |
| DB='memory.json' | |
| def _load(): | |
| if os.path.exists(DB): | |
| try: | |
| return json.load(open(DB,'r',encoding='utf-8')) | |
| except: | |
| return [] | |
| return [] | |
| def _save(data): | |
| json.dump(data, open(DB,'w',encoding='utf-8'), indent=2) | |
| def store(entry): | |
| data=_load(); data.append({'ts':__import__('datetime').datetime.utcnow().isoformat(),'entry':entry}); _save(data) | |
| def recall(limit=100): | |
| data=_load(); return data[-limit:] | |
| def clear(): | |
| _save([]) | |