5
5
import webbrowser
6
6
from http .server import BaseHTTPRequestHandler , HTTPServer
7
7
8
- from .explore import TripleCounter
8
+ from .explore import THIS_DIR , TripleCounter
9
9
10
10
11
11
def start_browser (server_ready_event , url ):
@@ -21,19 +21,43 @@ def jsonl_iterator(filename):
21
21
22
22
def main ():
23
23
parser = argparse .ArgumentParser (
24
- prog = "ProgramName" ,
25
- description = "What the program does" ,
26
- epilog = "Text at the bottom of help" ,
24
+ description = "visualize the structure and type of a group of JSONs" ,
27
25
)
28
26
parser .add_argument (
29
27
"filename" ,
30
28
help = "filename of a file in JSON Lines format" ,
29
+ nargs = "?" ,
30
+ default = None ,
31
+ )
32
+ parser .add_argument (
33
+ "--example" ,
34
+ help = "run with test data" ,
35
+ action = "store_true" ,
36
+ )
37
+ parser .add_argument (
38
+ "-p" ,
39
+ "--port" ,
40
+ default = 8001 ,
41
+ type = int ,
42
+ help = "port for server (default 8001)" ,
43
+ )
44
+ parser .add_argument (
45
+ "-n" ,
46
+ "--no-serve" ,
47
+ help = "write HTML to stdout instead of opening browser" ,
48
+ action = "store_true" ,
31
49
)
32
- parser .add_argument ("-p" , "--port" , default = 8001 , type = int , help = "port for server (default 8001)" )
33
- parser .add_argument ("-n" , "--no-serve" , help = "write HTML to stdout instead of serving" , action = "store_true" )
34
50
args = parser .parse_args ()
35
51
36
- counter = TripleCounter .from_objects (jsonl_iterator (args .filename ))
52
+ filename = args .filename
53
+ if not args .example and not args .filename :
54
+ parser .error ("filename is required (unless --example is given)" )
55
+ elif args .example and args .filename :
56
+ parser .error ("can't pass both filename and --example" )
57
+ elif args .example :
58
+ filename = THIS_DIR / "example1.jsonl"
59
+
60
+ counter = TripleCounter .from_objects (jsonl_iterator (filename ))
37
61
response_text = counter .html ()
38
62
39
63
if args .no_serve :
0 commit comments