Buckets:
| from __future__ import annotations | |
| __all__ = ["Note"] | |
| import os | |
| from pydantic import BaseModel | |
| import aiofiles | |
| from .versioning import gitAdd, gitSave | |
| from .configuration import PATH | |
| class Note(BaseModel): | |
| "A markdown note" | |
| name: str | |
| content: str = "" | |
| def exists(self) -> bool: | |
| return os.path.exists(self.filename) | |
| def filename(self) -> str: | |
| return os.path.join(PATH, self.name) + ".md" | |
| async def load(name) -> Note: | |
| n = Note(name=name) | |
| async with aiofiles.open(n.filename, "r", encoding="utf-8") as f: | |
| n.content = await f.read() | |
| return n | |
| async def save(self, creation=False): | |
| if creation: # auto make directory if it doesn't exist | |
| rootDir = os.path.dirname(self.filename) | |
| if not os.path.exists(rootDir): | |
| os.makedirs(rootDir, exist_ok=True) | |
| async with aiofiles.open(self.filename, "w", encoding="utf-8") as f: | |
| await f.write(self.content) | |
| if creation: | |
| await gitAdd(self.name) | |
| await gitSave( | |
| self.name, | |
| f"Udated {self.name}" if not creation else f"NEW note: {self.name}", | |
| ) | |
Xet Storage Details
- Size:
- 1.24 kB
- Xet hash:
- 1b319df6e35908b546e1b4b17e51faa925dc07e2415a247ee6581b542c48b1a6
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.