blob: 8e2fcb1fe1b96a3713142803557ce58febda9423 (
plain)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#!/bin/bash
# Configuration
USER_AGENTS_FILE="user_agents.txt"
OLLAMA_URL="http://localhost:11434/api/generate"
MODEL="llama3.2:latest"
MAX_LINES=$(wc -l < "${USER_AGENTS_FILE}" | xargs)
OUTPUT_FILE="bot_names_results.txt"
# ANSI color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if user_agents.txt exists
if [ ! -f "$USER_AGENTS_FILE" ]; then
echo -e "${RED}Error: $USER_AGENTS_FILE not found!${NC}"
exit 1
fi
# Function to call Ollama API
generate_bot_name() {
local user_agent="$1"
# Craft an improved prompt with examples and context
local prompt="You are a bot naming expert. Generate a SHORT, memorable name (1-3 words) for this web crawler/bot based on its user agent string.
Rules:
- Keep it simple and descriptive
- Use the actual bot/product name if clearly visible
- Make it memorable and easy to pronounce
- Avoid generic terms like 'Web Crawler' or 'Bot'
- Focus on the brand/service name when available
Examples of good names:
- For Googlebot user agent → 'Google Bot'
- For AhrefsBot user agent → 'Ahrefs Spider'
- For Slackbot user agent → 'Slack Bot'
- For meta-externalagent → 'Meta Agent'
- For MJ12bot → 'MJ12 Bot'
- For ClaudeBot → 'Claude Bot'
- For PetalBot → 'Petal Bot'
User Agent: $user_agent
Generate ONLY the bot name (nothing else):"
# Create JSON payload
local json_payload=$(jq -n \
--arg model "$MODEL" \
--arg prompt "$prompt" \
'{model: $model, prompt: $prompt, stream: false, temperature: 0.3}')
# Call Ollama API with timeout
local response=$(timeout 10 curl -s -X POST "$OLLAMA_URL" \
-H "Content-Type: application/json" \
-d "$json_payload")
# Check if curl timed out
if [ $? -eq 124 ]; then
echo "Request Timeout"
return
fi
# Extract the response text and clean it
local bot_name=$(echo "$response" | jq -r '.response' 2>/dev/null | \
tr -d '\n' | \
sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | \
sed 's/^"//;s/"$//' | \
head -n 1)
# If response is empty or too long, return error
if [ -z "$bot_name" ] || [ ${#bot_name} -gt 50 ]; then
echo "Generation Failed"
else
echo "$bot_name"
fi
}
# Main script
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN}Bot Name Generator - Processing first $MAX_LINES user agents${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo
# Initialize output file with header
{
echo "Bot Name Generation Results"
echo "Generated on: $(date)"
echo "Model: $MODEL"
echo "========================================="
echo
} > "$OUTPUT_FILE"
# Counter for limiting to first 20
count=0
successful=0
failed=0
# Store results for summary
declare -a results
declare -a bot_names_only
# Read file line by line
while IFS= read -r line && [ $count -lt $MAX_LINES ]; do
# Skip empty lines
if [ -z "$line" ]; then
continue
fi
# Increment counter
((count++))
echo -e "${YELLOW}[$count/$MAX_LINES]${NC} Processing..."
# Clean and truncate user agent for display
clean_line=$(echo "$line" | tr -d '"')
if [ ${#clean_line} -gt 70 ]; then
display_line="${clean_line:0:67}..."
else
display_line="$clean_line"
fi
echo -e " User Agent: ${BLUE}$display_line${NC}"
# Generate bot name
bot_name=$(generate_bot_name "$line")
# Check if generation was successful
if [[ "$bot_name" == "Generation Failed" ]] || [[ "$bot_name" == "Request Timeout" ]]; then
echo -e " Generated: ${RED}$bot_name${NC}"
((failed++))
results+=("FAILED|$display_line")
else
echo -e " Generated: ${GREEN}$bot_name${NC}"
((successful++))
results+=("$bot_name|$display_line")
bot_names_only+=("$bot_name")
# Save to file
{
echo "Entry #$count"
echo "User Agent: $line"
echo "Generated Name: $bot_name"
echo "-----------------------------------------"
echo
} >> "$OUTPUT_FILE"
fi
echo
# Small delay to avoid overwhelming the API
sleep 0.3
done < "$USER_AGENTS_FILE"
# Print summary
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN}Summary Report${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo -e "Total Processed: ${YELLOW}$count${NC}"
echo -e "Successful: ${GREEN}$successful${NC}"
echo -e "Failed: ${RED}$failed${NC}"
if [ $count -gt 0 ]; then
echo -e "Success Rate: ${GREEN}$(( successful * 100 / count ))%${NC}"
fi
echo
echo -e "${BLUE}Results saved to: ${YELLOW}$OUTPUT_FILE${NC}"
echo
# Display all results in a table format
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN}Generated Names Summary${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo
i=1
for result in "${results[@]}"; do
IFS='|' read -r name agent <<< "$result"
if [[ "$name" == "FAILED" ]]; then
printf "%2d. ${RED}%-25s${NC} <- %s\n" "$i" "[Failed]" "${agent:0:50}"
else
printf "%2d. ${GREEN}%-25s${NC} <- %s\n" "$i" "$name" "${agent:0:50}"
fi
((i++))
done
echo
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
# Save just the bot names to a separate file for easy use
if [ ${#bot_names_only[@]} -gt 0 ]; then
echo
echo -e "${YELLOW}Saving bot names list to: bot_names_only.txt${NC}"
printf "%s\n" "${bot_names_only[@]}" > bot_names_only.txt
fi
echo
echo -e "${GREEN}Script complete!${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
|