pup-py commited on
Commit
6d90cda
·
1 Parent(s): 14f478a

subprocess unconfusion

Browse files
Files changed (1) hide show
  1. fetch.py +4 -4
fetch.py CHANGED
@@ -105,11 +105,11 @@ def get_analytics(n: int = 5):
105
  if n == 0:
106
  cmd = f"tac {LOGFILE.as_posix()}"
107
  else:
108
- cmd = f"tail {n} {LOGFILE.as_posix()} | tac"
109
- _subprocess = subprocess.run(cmd.split(), capture_output=True)
110
- json_lines, stderr = _subprocess.stdout, _subprocess.stderr
111
  try:
112
- content = json.loads(f"[ {json_lines.replace(b"\n", b",").decode()} ]")
113
  return content
114
  except Exception as e:
115
  return {"error": str(e), "stderr": stderr, "json_lines": json_lines}
 
105
  if n == 0:
106
  cmd = f"tac {LOGFILE.as_posix()}"
107
  else:
108
+ cmd = f"tail -n {n} {LOGFILE.as_posix()} | tac"
109
+ _subprocess = subprocess.run(cmd, shell=True, text=True, capture_output=True)
110
+ json_lines, stderr = _subprocess.stdout[-1], _subprocess.stderr
111
  try:
112
+ content = json.loads(f"[ {json_lines.replace("\n", ",")} ]")
113
  return content
114
  except Exception as e:
115
  return {"error": str(e), "stderr": stderr, "json_lines": json_lines}