import io import locale import os import sys import json def safe_open(path, mode): # some systems have non ut8 encodings which causes an exception # that spams /var/log/messages return io.open(file= path, mode = mode,encoding = locale.getpreferredencoding(False), errors='replace') filepath = sys.argv[0] try: with safe_open(filepath, 'rt') as f: lines = len(f.readlines()) size = -1 size = os.stat(filepath).st_size except: pass output = dict(scriptVersion=1, bash_history_linecount=lines, bash_history_size=size) sys.stdout.write(json.dumps(output))