diff --git a/scripts/daily-digest.sh b/scripts/daily-digest.sh new file mode 100755 index 0000000..e2c4088 --- /dev/null +++ b/scripts/daily-digest.sh @@ -0,0 +1,147 @@ +#!/bin/bash +# Daily Digest Generator Script +# Generates and posts daily digest to blog-backup +# Usage: ./daily-digest.sh [YYYY-MM-DD] + +set -euo pipefail + +# Configuration +BLOG_API_URL="${BLOG_API_URL:-https://blog-backup-two.vercel.app/api}" +BLOG_MACHINE_TOKEN="${BLOG_MACHINE_TOKEN:-daily-digest-2026-secure-key}" +DATE="${1:-$(date +%Y-%m-%d)}" + +# Validate date format +if [[ ! "$DATE" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then + echo "Error: Date must be in YYYY-MM-DD format" >&2 + exit 1 +fi + +# Get day name for title +DAY_NAME=$(date -j -f "%Y-%m-%d" "$DATE" "+%A" 2>/dev/null || date -d "$DATE" "+%A") +MONTH_NAME=$(date -j -f "%Y-%m-%d" "$DATE" "+%B" 2>/dev/null || date -d "$DATE" "+%B") +DAY_NUM=$(date -j -f "%Y-%m-%d" "$DATE" "+%d" 2>/dev/null || date -d "$DATE" "+%d") +YEAR=$(date -j -f "%Y-%m-%d" "$DATE" "+%Y" 2>/dev/null || date -d "$DATE" "+%Y") + +TITLE="# Daily Digest - $DAY_NAME, $MONTH_NAME $DAY_NUM, $YEAR" + +# Check if digest already exists +echo "Checking for existing digest on $DATE..." +EXISTING=$(curl -s "${BLOG_API_URL}/messages?limit=1&since=${DATE}" \ + -H "x-api-key: ${BLOG_MACHINE_TOKEN}") + +if echo "$EXISTING" | jq -e 'length > 0' >/dev/null 2>&1; then + echo "Digest already exists for $DATE. Skipping." + exit 0 +fi + +echo "Generating digest for $DATE..." + +# Create digest content +# Note: This is a template - the actual content should be generated by research +CONTENT=$(cat < "$TEMP_FILE" + +echo "Posting digest to blog..." + +# Post to blog API +RESPONSE=$(curl -s -X POST "${BLOG_API_URL}/digest" \ + -H "Content-Type: application/json" \ + -H "x-api-key: ${BLOG_MACHINE_TOKEN}" \ + --data-binary "@$TEMP_FILE") + +# Clean up temp file +rm -f "$TEMP_FILE" + +# Check response +if echo "$RESPONSE" | jq -e '.success' >/dev/null 2>&1; then + DIGEST_ID=$(echo "$RESPONSE" | jq -r '.id') + echo "✅ Digest posted successfully!" + echo "ID: $DIGEST_ID" + echo "URL: https://blog-backup-two.vercel.app" + exit 0 +else + echo "❌ Failed to post digest" >&2 + echo "Response: $RESPONSE" >&2 + exit 1 +fi