subprocess unconfusion
Browse files
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
|
110 |
-
json_lines, stderr = _subprocess.stdout, _subprocess.stderr
|
111 |
try:
|
112 |
-
content = json.loads(f"[ {json_lines.replace(
|
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}
|