import sys import os import json from util import import_data, ui_import_data, value_counter, ui_counts_to_columns if __name__ == "__main__": if len(sys.argv) == 2: # Count values associated with key, human friendly output. search_key = sys.argv[1] where_key = None where_value = None json_data = ui_import_data() stats, num_matches = value_counter(json_data, search_key, where_key, where_value) if not stats: print("Sorry, didn't find any stats for '%s' in the JSON." % search_key) sys.exit(1) title = "Count of values from field '%s'" % search_key print("\n\n%s" % title) print("(Data from %s out of %s blobs)" % (num_matches, len(json_data))) print("-" * len(title)) ui_counts_to_columns(stats) elif len(sys.argv) == 3 and sys.argv[2] == "--json": # Count values associated with key, machine output. search_key = sys.argv[1] where_key = None where_value = None
if __name__ == "__main__": args = parser.parse_args() search_key = args.key json_data, load_errors = import_data(json_fmatch=args.fnmatch) if load_errors: # If we start getting unexpected JSON or other things, might need to # revisit quitting on load_errors print("Error loading JSON data.") for e in load_errrors: print(e) sys.exit(1) elif not json_data: print("No data loaded.") sys.exit(1) stats, num_matches = value_counter(json_data, search_key, args.where) if not stats: print("Nothing found.") sys.exit(1) if args.human: title = "Count of values from field '%s'" % search_key print("\n\n%s" % title) print("(Data from %s out of %s blobs)" % (num_matches, len(json_data))) print("-" * len(title)) ui_counts_to_columns(stats) else: print(json.dumps(stats))
args = parser.parse_args() search_key = args.key json_data, load_errors = import_data(json_fmatch=args.fnmatch) if load_errors: # If we start getting unexpected JSON or other things, might need to # revisit quitting on load_errors print("Error loading JSON data.") for e in load_errors: print(e) sys.exit(1) elif not json_data: print("No data loaded.") sys.exit(1) stats, num_matches = value_counter(json_data, search_key, args.where) if not stats: print("Nothing found.") sys.exit(1) if args.human and args.list: print("\n".join(sorted(stats.keys()))) elif args.human: title = "Count of values from field '%s'" % search_key print("\n\n%s" % title) print("(Data from %s out of %s blobs)" % (num_matches, len(json_data))) print("-" * len(title)) ui_counts_to_columns(stats) elif args.list: print(json.dumps(sorted(stats.keys())))
import sys import os import json from util import import_data, ui_import_data, value_counter, ui_values_to_columns if __name__ == "__main__": if len(sys.argv) == 2: # Count values associated with key, human friendly output. search_key = sys.argv[1] where_key = None where_value = None json_data = ui_import_data() stats, num_matches = value_counter(json_data, search_key, where_key, where_value) if not stats: print("Sorry, didn't find any stats for '%s' in the JSON." % search_key) sys.exit(1) title = "List of values from field '%s'" % search_key print("\n\n%s" % title) print("(Data from %s out of %s blobs)" % (num_matches, len(json_data))) print("-" * len(title)) ui_values_to_columns(sorted(stats.keys())) elif len(sys.argv) == 3 and sys.argv[2] == "--json": # Count values associated with key, machine output. search_key = sys.argv[1] where_key = None where_value = None