-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_daily.sh
More file actions
executable file
·139 lines (121 loc) · 4.12 KB
/
run_daily.sh
File metadata and controls
executable file
·139 lines (121 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
#
# The D-AI-LY - Autonomous Daily Pipeline
#
# This script orchestrates the full workflow:
# 1. Discover newsworthy tables
# 2. Fetch data for selected table(s)
# 3. Generate articles (via Claude Code)
# 4. Build and publish site
#
# Usage: ./run_daily.sh [--dry-run] [--table TABLE_NUMBER]
#
# Options:
# --dry-run Run discovery only, don't generate or publish
# --table NUM Skip discovery and process specific table
set -e
# Configuration
OUTPUT_DIR="output"
DOCS_DIR="docs"
# Parse arguments
DRY_RUN=false
SPECIFIC_TABLE=""
for arg in "$@"; do
case $arg in
--dry-run)
DRY_RUN=true
shift
;;
--table)
SPECIFIC_TABLE="$2"
shift 2
;;
--table=*)
SPECIFIC_TABLE="${arg#*=}"
shift
;;
esac
done
echo "═══════════════════════════════════════════════════════════════════"
echo " THE D-AI-LY - Autonomous Pipeline"
echo " $(date '+%Y-%m-%d %H:%M:%S')"
echo "═══════════════════════════════════════════════════════════════════"
echo ""
# Ensure output directory exists
mkdir -p "$OUTPUT_DIR"
# Step 1: Discover topics (or use specific table)
if [ -n "$SPECIFIC_TABLE" ]; then
echo "📌 Using specified table: $SPECIFIC_TABLE"
SELECTED_TABLE="$SPECIFIC_TABLE"
else
echo "🔍 Step 1: Discovering newsworthy topics..."
Rscript r-tools/discover_topics.R --configured --json --output="$OUTPUT_DIR"
# Read recommendation from JSON
if [ -f "$OUTPUT_DIR/discovery_results.json" ]; then
SELECTED_TABLE=$(python3 -c "
import json
with open('$OUTPUT_DIR/discovery_results.json') as f:
data = json.load(f)
if data.get('recommendation'):
print(data['recommendation']['table_number'])
")
echo ""
echo "📊 Recommended table: $SELECTED_TABLE"
else
echo "❌ Discovery failed - no results file"
exit 1
fi
fi
if [ -z "$SELECTED_TABLE" ]; then
echo "⚠️ No table selected. No newsworthy updates found."
exit 0
fi
if [ "$DRY_RUN" = true ]; then
echo ""
echo "🏃 Dry run mode - stopping before data fetch"
exit 0
fi
# Step 2: Fetch data
echo ""
echo "📥 Step 2: Fetching data for table $SELECTED_TABLE..."
Rscript r-tools/fetch_table.R "$SELECTED_TABLE" "$OUTPUT_DIR"
# Check for output file
DATA_FILE="$OUTPUT_DIR/data_${SELECTED_TABLE//-/_}.json"
if [ ! -f "$DATA_FILE" ]; then
echo "❌ Data fetch failed - no output file"
exit 1
fi
echo "✅ Data saved to: $DATA_FILE"
# Step 3: Generate article
# NOTE: This step requires Claude Code to be invoked
# In an automated environment, this would call the Claude API
echo ""
echo "📝 Step 3: Article generation required"
echo ""
echo "To generate the article, run Claude Code with:"
echo ""
echo " /the-daily-generator $SELECTED_TABLE"
echo ""
echo "Or manually:"
echo " 1. Review data: cat $DATA_FILE"
echo " 2. Create article in docs/en/<slug>/index.md"
echo " 3. Create French version in docs/fr/<slug>/index.md"
echo " 4. Update docs/en/index.md and docs/fr/index.md"
echo " 5. Run: npm run build"
echo ""
# For fully automated mode (with Claude API), uncomment:
# claude --prompt "Generate articles for table $SELECTED_TABLE using /the-daily-generator"
# Step 4: Build (only if articles exist)
# echo ""
# echo "🔨 Step 4: Building site..."
# npm run build
# Step 5: Publish (only if build succeeds)
# echo ""
# echo "🚀 Step 5: Publishing..."
# git add docs/ output/
# git commit -m "Add: <headline> - generated by D-AI-LY"
# git push
echo ""
echo "═══════════════════════════════════════════════════════════════════"
echo " Pipeline complete. Review and run /the-daily-generator"
echo "═══════════════════════════════════════════════════════════════════"