MCPcopy Create free account
hub / github.com/NanmiCoder/MediaCrawler / get_file_info

Function get_file_info

api/routers/data.py:33–58  ·  view source on GitHub ↗

Get file information

(file_path: Path)

Source from the content-addressed store, hash-verified

31
32
33def get_file_info(file_path: Path) -> dict:
34 """Get file information"""
35 stat = file_path.stat()
36 record_count = None
37
38 # Try to get record count
39 try:
40 if file_path.suffix == ".json":
41 with open(file_path, "r", encoding="utf-8") as f:
42 data = json.load(f)
43 if isinstance(data, list):
44 record_count = len(data)
45 elif file_path.suffix == ".csv":
46 with open(file_path, "r", encoding="utf-8") as f:
47 record_count = sum(1 for _ in f) - 1 # Subtract header row
48 except Exception:
49 pass
50
51 return {
52 "name": file_path.name,
53 "path": str(file_path.relative_to(DATA_DIR)),
54 "size": stat.st_size,
55 "modified_at": stat.st_mtime,
56 "record_count": record_count,
57 "type": file_path.suffix[1:] if file_path.suffix else "unknown"
58 }
59
60
61@router.get("/files")

Callers 1

list_data_filesFunction · 0.85

Calls 1

sumFunction · 0.85

Tested by

no test coverage detected