-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
25 lines (19 loc) · 738 Bytes
/
Copy pathutils.py
File metadata and controls
25 lines (19 loc) · 738 Bytes
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
from typing import List, Any
from datetime import date, datetime
import json
import os
def _json_default(value: Any):
if isinstance(value, (datetime, date)):
return value.isoformat()
raise TypeError(
f"Object of type {value.__class__.__name__} is not JSON serializable")
def writeJson(filename: str, data: List[Any] = []):
os.makedirs("./cache", exist_ok=True)
full_path = os.path.join("./cache", filename)
with open(full_path, "w") as file:
json.dump(data, file, indent=4, default=_json_default)
def readJson(filename: str):
os.makedirs("./cache", exist_ok=True)
full_path = os.path.join("./cache", filename)
with open(full_path, "r") as file:
return json.load(file)