diff options
| author | hrbrmstr <bob@rud.is> | 2025-09-05 14:40:22 -0400 |
|---|---|---|
| committer | hrbrmstr <bob@rud.is> | 2025-09-05 14:40:22 -0400 |
| commit | 4fbf73520a8850d4b966aace9ee4af945bfdfe58 (patch) | |
| tree | 3cd1b0a133f731a9c0fa4c598836ab5b88856cfd /2025/2025-09-05-generate-bot-names.sh | |
| parent | 6027fb61426b5dd26bc8b0ecd2711c6f20498a99 (diff) | |
add: user-agent table and bash script
Diffstat (limited to '2025/2025-09-05-generate-bot-names.sh')
| -rwxr-xr-x | 2025/2025-09-05-generate-bot-names.sh | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/2025/2025-09-05-generate-bot-names.sh b/2025/2025-09-05-generate-bot-names.sh new file mode 100755 index 0000000..8e2fcb1 --- /dev/null +++ b/2025/2025-09-05-generate-bot-names.sh @@ -0,0 +1,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}" |
