Ver código fonte

[bin] Update cocktail of webcam scripts

Colin Powell 1 dia atrás
pai
commit
c80a0894bc

+ 9 - 2
bin/.bin/checkworkmail.py

@@ -30,6 +30,7 @@ SLACK_SENDER = "notification@slack.com"
 GITHUB_SENDER = "notifications@github.com"
 JIRA_BASE_URL = os.getenv("JIRA_BASE_URL", "https://yourcompany.atlassian.net/browse")
 
+GH_STATE_AND_TITLE_TO_SKIP = ["New Relic Exporter", "cancelled", "skipped", "succeeded"]
 # ----------------------
 # HELPERS
 # ----------------------
@@ -179,8 +180,14 @@ def check_notifications():
             continue
 
         message = format_message(source, subject, body, link)
-        print(f"Sending {source} notification: {subject}")
-        send_ntfy_notification(subject, message)
+        send_notice = True
+        for exclusion in GH_STATE_AND_TITLE_TO_SKIP:
+            if exclusion in subject:
+                print(f"Skipping notification: {subject}")
+                send_notice = False
+        if send_notice:
+            print(f"Sending {source} notification: {subject}")
+            send_ntfy_notification(subject, message)
         archive_message(mail, num)
 
     mail.expunge()

+ 126 - 0
bin/.bin/webcam-build-timelapses

@@ -0,0 +1,126 @@
+#!/usr/bin/env bash
+# run_all_timelapses.sh
+#
+# Run timelapse creation for a fixed set of webcams,
+# collect public URLs, update HTML index, and send one combined ntfy notification.
+#
+# Requirements: make_timelapse.sh in same folder or PATH
+
+set -euo pipefail
+
+# --- Settings ---
+BASE_DIR="/media/photos/misc/webcams"
+INDEX_FILE="$BASE_DIR/timelapses.html"
+WEBCAMS=(
+  "frontyard"
+  "basement_table"
+  "mailbox"
+  "basement_extension"
+  "backyard_low"
+  "backyard_north"
+  "basement_cape"
+  "basement_tv"
+  "backyard"
+  "bulkhead"
+  "barn"
+  "garage"
+  "birds"
+  "porch"
+  "garden"
+  "diningroom"
+)
+TIMELAPSE_SCRIPT="/usr/local/bin/make_timelapse"
+
+NTFY_URL="https://ntfy.unbl.ink/timelapse"
+WEB_PREFIX="https://files.lab.unbl.ink"
+# ----------------
+
+# Yesterday's date
+if date -d "yesterday" +%Y >/dev/null 2>&1; then
+  # GNU date (Linux)
+  YESTERDAY=$(date -d "yesterday" +"%Y/%m/%d")
+else
+  # BSD date (macOS)
+  YESTERDAY=$(date -v-1d +"%Y/%m/%d")
+fi
+
+LINKS=()
+
+for cam in "${WEBCAMS[@]}"; do
+  TARGET_DIR="$BASE_DIR/$cam/$YESTERDAY"
+
+  if [[ -d "$TARGET_DIR" ]]; then
+    echo "📷 Processing $cam ($TARGET_DIR)"
+    OUTPUT=$("$TIMELAPSE_SCRIPT" "$TARGET_DIR")
+    echo "$OUTPUT"
+
+    LINK="$WEB_PREFIX/$cam/$YESTERDAY/timelapse.mp4"
+    if [[ -f "$TARGET_DIR/timelapse.mp4" ]]; then
+      LINKS+=("[$cam] $LINK")
+    fi
+  else
+    echo "⚠️ Skipping $cam (no folder for $YESTERDAY)"
+  fi
+done
+
+# --- Update HTML index ---
+mkdir -p "$BASE_DIR"
+if [[ ! -f "$INDEX_FILE" ]]; then
+  cat >"$INDEX_FILE" <<EOF
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>Webcam Timelapses</title>
+  <style>
+    body { font-family: sans-serif; padding: 1em; background: #f9f9f9; }
+    h2 { margin-top: 1.5em; }
+    ul { list-style: none; padding: 0; }
+    li { margin: 0.3em 0; }
+    a { text-decoration: none; color: #0366d6; }
+    a:hover { text-decoration: underline; }
+  </style>
+</head>
+<body>
+  <h1>Webcam Timelapses</h1>
+</body>
+</html>
+EOF
+fi
+
+# Insert new section for yesterday at the top
+TMP=$(mktemp)
+{
+  echo "<h2>$YESTERDAY</h2>"
+  echo "<ul>"
+  for entry in "${LINKS[@]}"; do
+    cam="${entry%%]*}"
+    cam="${cam#[}"
+    url="${entry#* }"
+    echo "  <li><a href=\"$url\">$cam</a></li>"
+  done
+  echo "</ul>"
+  echo "<hr>"
+} >"$TMP"
+
+# Place new block after <h1> line
+awk -v block="$(cat "$TMP")" '
+  /<h1>/ { print; getline; print; print block; next }
+  { print }
+' "$INDEX_FILE" >"$INDEX_FILE.new"
+
+mv "$INDEX_FILE.new" "$INDEX_FILE"
+rm "$TMP"
+
+echo "📄 Updated HTML index: $INDEX_FILE"
+
+# --- Send combined notification ---
+if [[ -n "$NTFY_URL" ]] && [[ ${#LINKS[@]} -gt 0 ]]; then
+  MSG="Timelapses for $YESTERDAY:\n$(printf '%s\n' "${LINKS[@]}")"
+  curl -s -H "Title: Timelapses complete" \
+       -H "Priority: high" \
+       -d "$MSG" \
+       "$NTFY_URL" >/dev/null || true
+  echo "📢 Combined notification sent to ntfy."
+fi
+

+ 29 - 29
bin/.bin/webcam-capture

@@ -11,55 +11,39 @@ if [ "$1" = "frontyard" ]; then
   host="loge.local"
   port=8082
 fi
-if [ "$1" = "house" ]; then
-  port=8083
-  host="kiviuq.local"
+if [ "$1" = "basement_tv" ]; then
+  port=8081
+  host="polydeuces.local"
 fi
 if [ "$1" = "basement_cape" ]; then
   port=8081
   host="kiviuq.local"
 fi
-if [ "$1" = "basement_cape_2" ]; then
-  port=8081
-  host="bebhionn.local"
-fi
 if [ "$1" = "bulkhead" ]; then
   port=8082
   host="kiviuq.local"
 fi
 if [ "$1" = "backyard" ]; then
-  port=8084
-  host="paaliaq.local"
+  port=8082
+  host="mundilfari.local"
 fi
 if [ "$1" = "backyard_low" ]; then
-  port=8081
-  host="paaliaq.local"
+  port=8083
+  host="mundilfari.local"
 fi
 if [ "$1" = "backyard_north" ]; then
-  port=8082
-  host="paaliaq.local"
+  port=8084
+  host="mundilfari.local"
 fi
 if [ "$1" = "basement_extension" ]; then
-  port=8083
-  host="paaliaq.local"
-fi
-if [ "$1" = "diningroom" ]; then
-  port=8082
-  host="kari.local"
-fi
-if [ "$1" = "livingroom" ]; then
   port=8081
-  host="mimas.local"
-fi
-if [ "$1" = "christmas_tree" ]; then
-  port=8083
-  host="mimas.local"
+  host="mundilfari.local"
 fi
 if [ "$1" = "orchard" ]; then
   port=8081
   host="mobian.local"
 fi
-if [ "$1" = "chicks" ]; then
+if [ "$1" = "barn" ]; then
   port=8083
   host="iapetus.local"
 fi
@@ -67,9 +51,25 @@ if [ "$1" = "garage" ]; then
   port=8082
   host="iapetus.local"
 fi
-if [ "$1" = "barn" ]; then
+if [ "$1" = "chicks" ]; then
+  port=8081
+  host="iapetus.local"
+fi
+if [ "$1" = "porch" ]; then
   port=8081
-  host="pan.local"
+  host="siarnaq.local"
+fi
+if [ "$1" = "birds" ]; then
+  port=8082
+  host="siarnaq.local"
+fi
+if [ "$1" = "garden" ]; then
+  port=8083
+  host="siarnaq.local"
+fi
+if [ "$1" = "diningroom" ]; then
+  port=8081
+  host="kari.local"
 fi
 
 ROOT="/var/photos/misc/webcams"

+ 6 - 4
bin/.bin/webcam-capture-all

@@ -1,16 +1,18 @@
 #!/bin/bash
 
 /home/powellc/.bin/webcam-capture frontyard
-/home/powellc/.bin/webcam-capture basement_table
 /home/powellc/.bin/webcam-capture mailbox
+/home/powellc/.bin/webcam-capture basement_table
+/home/powellc/.bin/webcam-capture basement_tv
 /home/powellc/.bin/webcam-capture basement_extension
 /home/powellc/.bin/webcam-capture backyard_low
 /home/powellc/.bin/webcam-capture backyard_north
 /home/powellc/.bin/webcam-capture basement_cape
-/home/powellc/.bin/webcam-capture house
 /home/powellc/.bin/webcam-capture backyard
 /home/powellc/.bin/webcam-capture bulkhead
-/home/powellc/.bin/webcam-capture orchard
-/home/powellc/.bin/webcam-capture chicks
 /home/powellc/.bin/webcam-capture barn 
 /home/powellc/.bin/webcam-capture garage 
+/home/powellc/.bin/webcam-capture birds
+/home/powellc/.bin/webcam-capture porch
+/home/powellc/.bin/webcam-capture garden
+/home/powellc/.bin/webcam-capture diningroom