pull_feedback: highlight new submissions since last pull

This commit is contained in:
Davide Scaini
2026-05-13 20:36:40 +02:00
parent b5a1e881fb
commit fc012b5311
+62 -9
View File
@@ -6,17 +6,70 @@ set -e
VPS=${1:?Usage: $0 user@host} VPS=${1:?Usage: $0 user@host}
REMOTE=/var/bincio/data/_feedback REMOTE=/var/bincio/data/_feedback
LOCAL=$(dirname "$0")/../feedback LOCAL=$(dirname "$0")/../feedback
SEEN="$LOCAL/.seen"
mkdir -p "$LOCAL" mkdir -p "$LOCAL"
echo "Syncing feedback from $VPS:$REMOTE$LOCAL" echo "Syncing feedback from $VPS:$REMOTE$LOCAL"
rsync -avz --progress "${VPS}:${REMOTE}/" "$LOCAL/" rsync -az "${VPS}:${REMOTE}/" "$LOCAL/"
echo "" python3 - "$LOCAL" "$SEEN" <<'EOF'
echo "=== Feedback summary ===" import json, sys, os
for f in "$LOCAL"/*.json; do from datetime import datetime, timezone
[[ -f "$f" ]] || continue
handle=$(basename "$f" .json) local_dir, seen_file = sys.argv[1], sys.argv[2]
count=$(python3 -c "import json,sys; d=json.load(open('$f')); print(len(d) if isinstance(d, list) else 1)" 2>/dev/null || echo "?")
echo " @$handle: $count submission(s)" seen = set()
done if os.path.exists(seen_file):
seen = set(json.loads(open(seen_file).read()))
new_entries = []
all_ids = []
for fname in sorted(os.listdir(local_dir)):
if not fname.endswith('.json') or fname.startswith('.'):
continue
handle = fname[:-5]
try:
entries = json.load(open(os.path.join(local_dir, fname)))
if not isinstance(entries, list):
entries = [entries]
except Exception:
continue
for e in entries:
eid = e.get('id', '')
all_ids.append(eid)
if eid not in seen:
new_entries.append((handle, e))
if new_entries:
print(f'\n\033[1;32m=== {len(new_entries)} new submission(s) ===\033[0m')
for handle, e in new_entries:
ts = e.get('submitted_at', '')[:10]
text = e.get('text', '').replace('\n', ' ')
images = e.get('images', [])
img_note = f' [{len(images)} image(s)]' if images else ''
print(f'\n \033[1m@{handle}\033[0m {ts}')
if text:
print(f' {text[:200]}{"…" if len(text) > 200 else ""}')
if img_note:
print(f' {img_note}')
else:
print('\n=== No new feedback ===')
# Print totals
print('\n--- totals ---')
for fname in sorted(os.listdir(local_dir)):
if not fname.endswith('.json') or fname.startswith('.'):
continue
handle = fname[:-5]
try:
entries = json.load(open(os.path.join(local_dir, fname)))
count = len(entries) if isinstance(entries, list) else 1
print(f' @{handle}: {count}')
except Exception:
pass
# Save updated seen set
open(seen_file, 'w').write(json.dumps(list(set(all_ids))))
EOF