28 lines
952 B
Python
28 lines
952 B
Python
import asyncio
|
|
from pathlib import Path
|
|
from watchfiles import awatch, Change
|
|
from .config import CONFIG
|
|
from .ingest import ingest_file
|
|
from .parsers import PARSERS
|
|
|
|
|
|
async def watch_corpus():
|
|
print(f"Watching {CONFIG.corpus_root} for changes...", flush=True)
|
|
async for changes in awatch(CONFIG.corpus_root):
|
|
for change_type, path_str in changes:
|
|
path = Path(path_str)
|
|
if path.suffix.lower() not in PARSERS:
|
|
continue
|
|
if change_type in (Change.added, Change.modified):
|
|
if path.is_file():
|
|
print(f"Change detected: {path}", flush=True)
|
|
try:
|
|
result = ingest_file(path)
|
|
print(f" → {result['status']}", flush=True)
|
|
except Exception as e:
|
|
print(f" → error: {e}", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(watch_corpus())
|