forked from AUTOMATIC1111/stable-diffusion-webui-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_json.py
56 lines (44 loc) · 1.26 KB
/
validate_json.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
import datetime
def operation(
*,
path_in: Path,
path_out: Path,
) -> None:
with path_in.open() as inf, path_out.open("w") as outf:
d = json.load(inf)
assert "tags" in d
tags = set(d["tags"].keys())
for extension in d["extensions"]:
for required_key in [
"name",
"url",
"description",
"description",
"added",
"tags",
]:
assert required_key in extension
for _tag in extension["tags"]:
assert _tag in tags
datetime.date.fromisoformat(extension['added']), "Incorrect data format, should be YYYY-MM-DD"
def get_opts() -> argparse.Namespace:
oparser = argparse.ArgumentParser()
oparser.add_argument(
"--input", "-i", type=Path, default="/dev/stdin", required=False
)
oparser.add_argument(
"--output", "-o", type=Path, default="/dev/stdout", required=False
)
return oparser.parse_args()
def main() -> None:
opts = get_opts()
operation(
path_in=opts.input,
path_out=opts.output,
)
if __name__ == "__main__":
main()