fix(last-run): guard python3 absence + hoist datetime + use context manager
This commit is contained in:
@@ -74,15 +74,16 @@ else
|
|||||||
LAST_RUN_FILE="$HOME/.config/last30days/last-run.json"
|
LAST_RUN_FILE="$HOME/.config/last30days/last-run.json"
|
||||||
fi
|
fi
|
||||||
LAST_RUN_LINE=""
|
LAST_RUN_LINE=""
|
||||||
if [[ -n "$LAST_RUN_FILE" && -f "$LAST_RUN_FILE" ]]; then
|
if [[ -n "$LAST_RUN_FILE" && -f "$LAST_RUN_FILE" ]] && command -v python3 &>/dev/null; then
|
||||||
LAST_RUN_LINE=$(LAST_RUN_FILE="$LAST_RUN_FILE" python3 - <<'PY' 2>/dev/null
|
LAST_RUN_LINE=$(LAST_RUN_FILE="$LAST_RUN_FILE" python3 - <<'PY' 2>/dev/null || true
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
path = os.environ["LAST_RUN_FILE"]
|
path = os.environ["LAST_RUN_FILE"]
|
||||||
try:
|
try:
|
||||||
d = json.load(open(path))
|
with open(path) as fh:
|
||||||
|
d = json.load(fh)
|
||||||
topic = (d.get("topic") or "?")[:60]
|
topic = (d.get("topic") or "?")[:60]
|
||||||
ts = d.get("timestamp", "")
|
ts = d.get("timestamp", "")
|
||||||
dt = datetime.datetime.fromisoformat(ts.replace("Z", "+00:00"))
|
dt = datetime.datetime.fromisoformat(ts.replace("Z", "+00:00"))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import atexit
|
import atexit
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -533,7 +534,6 @@ def _show_runtime_ui(
|
|||||||
|
|
||||||
def _write_last_run(topic: str, report: "schema.Report") -> None:
|
def _write_last_run(topic: str, report: "schema.Report") -> None:
|
||||||
try:
|
try:
|
||||||
import datetime
|
|
||||||
if env.CONFIG_DIR is None:
|
if env.CONFIG_DIR is None:
|
||||||
return
|
return
|
||||||
target = env.CONFIG_DIR
|
target = env.CONFIG_DIR
|
||||||
|
|||||||
Reference in New Issue
Block a user