Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/complete-agi-core / orchestrator/knowledge-sources.sh |
| Date | Not specified in source |
| Repository | Janady13/complete-agi-core |
| Revision | 33aa84f2aa61cedbe010240ada7f4efbdfe795a7 |
| Branch | claude/improve-math-logic-ehIW1 |
| Path or archive member | orchestrator/knowledge-sources.sh |
| Original SHA-256 | 353d9da28c0a3bdc83a5695024d53ffd660a5eea2db284aead564113b07c4373 |
| Git blob SHA | 59e39057fae26cd80959df8041def1d4e7a0fb5d |
| Reading-copy SHA-256 | d5ddb6a988269baad20c0e79825cba8af4bc9a01500bff6f9c8c304599195aed |
Recovered source transcript
Download complete source text ↓563 lines · 22.4 KB
Credential-bearing and unrelated personal details were removed from this reading copy. The source identity and original checksum remain recorded.
#!/bin/bash
# =============================================================================
# KNOWLEDGE SOURCES LIBRARY v3.0 - 500+ FREE APIs
# Massively expanded API library for autonomous AGI learning
# Used by MacBook 1 (purposeful-learner) and MacBook 2 (seferim-learner)
# =============================================================================
UA="AGIAGI/3.0 (autonomous-learning; contact@agi_core.ai)"
API_SOURCES_FILE="${HOME}/.agi_core/api_sources_500.json"
# =============================================================================
# CATEGORY: REFERENCE & KNOWLEDGE
# =============================================================================
fetch_wikipedia() {
local topic="$1"
local encoded=$(echo "$topic" | sed 's/ /%20/g; s/-/%20/g')
curl -s --max-time 10 \
"https://en.wikipedia.org/api/rest_v1/page/summary/$encoded" \
-H "User-Agent: $UA" | jq -r '.extract // empty' 2>/dev/null | head -c 1500
}
fetch_wikidata() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 8 \
"https://www.wikidata.org/w/api.php?action=wbsearchentities&search=$encoded&language=en&format=json" \
-H "User-Agent: $UA" | jq -r '.search[0] | "\(.label // ""): \(.description // "")"' 2>/dev/null
}
fetch_openlibrary() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /+/g')
curl -s --max-time 10 \
"https://openlibrary.org/search.json?q=$encoded&limit=1" \
-H "User-Agent: $UA" | \
jq -r '.docs[0] | "Book: \(.title // "") by \(.author_name[0] // "Unknown"). Published: \(.first_publish_year // "?")"' 2>/dev/null
}
fetch_gutenberg() {
curl -s --max-time 10 \
"https://gutendex.com/books/?page=$((RANDOM % 100 + 1))" \
-H "User-Agent: $UA" | \
jq -r '.results[0] | "Classic: \(.title // "") by \(.authors[0].name // "Unknown")"' 2>/dev/null
}
fetch_dictionary() {
local word="$1"
curl -s --max-time 8 \
"https://api.dictionaryapi.dev/api/v2/entries/en/$word" \
-H "User-Agent: $UA" | \
jq -r '.[0].meanings[0] | "\(.partOfSpeech): \(.definitions[0].definition)"' 2>/dev/null
}
fetch_datamuse() {
local word="$1"
local meanings=$(curl -s --max-time 5 "https://api.datamuse.com/words?sp=$word&md=d&max=1" -H "User-Agent: $UA" | jq -r '.[0].defs[0] // empty' 2>/dev/null)
local related=$(curl -s --max-time 5 "https://api.datamuse.com/words?ml=$word&max=5" -H "User-Agent: $UA" | jq -r '[.[].word] | join(", ")' 2>/dev/null)
echo "Definition: $meanings. Related: $related"
}
fetch_numbersapi() {
local number="${1:-random}"
curl -s --max-time 5 "http://numbersapi.com/$number/trivia" -H "User-Agent: $UA"
}
fetch_numbersapi_math() {
local number="${1:-random}"
curl -s --max-time 5 "http://numbersapi.com/$number/math" -H "User-Agent: $UA"
}
fetch_trivia() {
curl -s --max-time 8 \
"https://opentdb.com/api.php?amount=1&type=multiple" | \
jq -r '.results[0] | "Q: \(.question | gsub("""; "\"") | gsub("'"; "'\''")), A: \(.correct_answer)"' 2>/dev/null
}
fetch_quotable() {
local tag="$1"
local url="https://api.quotable.io/random"
[ -n "$tag" ] && url="$url?tags=$tag"
curl -s --max-time 5 "$url" -H "User-Agent: $UA" | jq -r '"\(.content) - \(.author)"' 2>/dev/null
}
fetch_zenquotes() {
curl -s --max-time 5 "https://zenquotes.io/api/random" | jq -r '.[0] | "\(.q) - \(.a)"' 2>/dev/null
}
fetch_poetrydb() {
curl -s --max-time 8 "https://poetrydb.org/random" | jq -r '.[0] | "Poem: \(.title) by \(.author)\n\(.lines[0:4] | join("\n"))"' 2>/dev/null
}
# =============================================================================
# CATEGORY: SCIENCE & RESEARCH
# =============================================================================
fetch_arxiv() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /+/g')
local result=$(curl -s --max-time 15 \
"http://export.arxiv.org/api/query?search_query=all:$encoded&start=0&max_results=1" \
-H "User-Agent: $UA")
local title=$(echo "$result" | sed -n 's/.*<title>\([^<]*\)<\/title>.*/\1/p' | head -2 | tail -1)
local summary=$(echo "$result" | sed -n 's/.*<summary>\([^<]*\)<\/summary>.*/\1/p' | head -1 | head -c 800)
echo "$title: $summary"
}
fetch_arxiv_random() {
local categories=("cs.AI" "cs.LG" "cs.CL" "cs.CV" "cs.NE" "stat.ML" "math.OC" "physics.comp-ph")
local cat="${categories[$RANDOM % ${#categories[@]}]}"
local result=$(curl -s --max-time 15 \
"http://export.arxiv.org/api/query?search_query=cat:$cat&sortBy=submittedDate&max_results=1" \
-H "User-Agent: $UA")
local title=$(echo "$result" | sed -n 's/.*<title>\([^<]*\)<\/title>.*/\1/p' | head -2 | tail -1)
local summary=$(echo "$result" | sed -n 's/.*<summary>\([^<]*\)<\/summary>.*/\1/p' | head -1 | head -c 600)
echo "[$cat] $title: $summary"
}
fetch_pubmed() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /+/g')
local ids=$(curl -s --max-time 8 \
"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=$encoded&retmax=1&retmode=json" | \
jq -r '.esearchresult.idlist[0]' 2>/dev/null)
if [ -n "$ids" ] && [ "$ids" != "null" ]; then
curl -s --max-time 8 \
"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=$ids&retmode=json" | \
jq -r '.result["'"$ids"'"] | "PubMed: \(.title // "")"' 2>/dev/null
fi
}
fetch_semantic_scholar() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://api.semanticscholar.org/graph/v1/paper/search?query=$encoded&limit=1&fields=title,abstract" \
-H "User-Agent: $UA" | \
jq -r '.data[0] | "\(.title // ""): \(.abstract // "")"' 2>/dev/null | head -c 1200
}
fetch_openalex() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://api.openalex.org/works?search=$encoded&per_page=1" \
-H "User-Agent: $UA" | \
jq -r '.results[0] | "OpenAlex: \(.title // "") - \(.publication_year // "")"' 2>/dev/null
}
fetch_crossref() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://api.crossref.org/works?query=$encoded&rows=1" \
-H "User-Agent: $UA" | \
jq -r '.message.items[0] | "Paper: \(.title[0] // ""). DOI: \(.DOI // ""). Citations: \(."is-referenced-by-count" // 0)"' 2>/dev/null
}
fetch_nasa_apod() {
curl -s --max-time 10 \
"https://api.nasa.gov/planetary/apod?api_key=[credential removed]" \
-H "User-Agent: $UA" | \
jq -r '"NASA APOD: \(.title // ""): \(.explanation // "")"' 2>/dev/null | head -c 800
}
fetch_spacex() {
curl -s --max-time 8 \
"https://api.spacexdata.com/v4/launches/latest" \
-H "User-Agent: $UA" | \
jq -r '"SpaceX Launch: \(.name // "") on \(.date_utc // "")"' 2>/dev/null
}
fetch_usgs_earthquakes() {
curl -s --max-time 10 \
"https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&limit=1&orderby=time" | \
jq -r '.features[0].properties | "Earthquake: M\(.mag // "?") - \(.place // "")"' 2>/dev/null
}
fetch_gbif() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://api.gbif.org/v1/species/search?q=$encoded&limit=1" \
-H "User-Agent: $UA" | \
jq -r '.results[0] | "Species: \(.scientificName // "") - \(.vernacularName // "")"' 2>/dev/null
}
fetch_inaturalist() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://api.inaturalist.org/v1/observations?q=$encoded&per_page=1" \
-H "User-Agent: $UA" | \
jq -r '.results[0] | "Observation: \(.species_guess // "") at \(.place_guess // "")"' 2>/dev/null
}
fetch_chembl() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://www.ebi.ac.uk/chembl/api/data/molecule/search?q=$encoded&format=json&limit=1" \
-H "User-Agent: $UA" | \
jq -r '.molecules[0] | "Molecule: \(.pref_name // "") - \(.molecule_chembl_id // "")"' 2>/dev/null
}
# =============================================================================
# CATEGORY: NEWS & TECH
# =============================================================================
fetch_hackernews() {
local story_id=$(curl -s --max-time 5 \
"https://hacker-news.firebaseio.com/v0/topstories.json" | \
jq -r ".[$((RANDOM % 30))]" 2>/dev/null)
if [ -n "$story_id" ]; then
curl -s --max-time 5 \
"https://hacker-news.firebaseio.com/v0/item/$story_id.json" | \
jq -r '"HackerNews: \(.title // "") | \(.url // "")"' 2>/dev/null
fi
}
fetch_hackernews_new() {
local story_id=$(curl -s --max-time 5 \
"https://hacker-news.firebaseio.com/v0/newstories.json" | \
jq -r ".[$((RANDOM % 30))]" 2>/dev/null)
if [ -n "$story_id" ]; then
curl -s --max-time 5 \
"https://hacker-news.firebaseio.com/v0/item/$story_id.json" | \
jq -r '"HN New: \(.title // "") | \(.url // "")"' 2>/dev/null
fi
}
fetch_lobsters() {
curl -s --max-time 8 \
"https://lobste.rs/hottest.json" | \
jq -r ".[$((RANDOM % 20))] | \"Lobsters: \(.title // \"\") | \(.url // \"\")\"" 2>/dev/null
}
fetch_devto() {
curl -s --max-time 8 \
"https://dev.to/api/articles?per_page=10" \
-H "User-Agent: $UA" | \
jq -r ".[$((RANDOM % 10))] | \"Dev.to: \(.title // \"\") by \(.user.name // \"\")\"" 2>/dev/null
}
fetch_reddit() {
local subreddit="${1:-technology}"
curl -s --max-time 10 \
"https://www.reddit.com/r/$subreddit/top.json?limit=10&t=day" \
-H "User-Agent: $UA" | \
jq -r ".data.children[$((RANDOM % 10))].data | \"Reddit r/$subreddit: \(.title // \"\")\"" 2>/dev/null
}
fetch_spaceflight_news() {
curl -s --max-time 8 \
"https://api.spaceflightnewsapi.net/v4/articles/?limit=10" | \
jq -r ".results[$((RANDOM % 10))] | \"Space News: \(.title // \"\")\"" 2>/dev/null
}
# =============================================================================
# CATEGORY: DEVELOPMENT & CODE
# =============================================================================
fetch_github() {
local topic="$1"
local encoded=$(echo "$topic" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://api.github.com/search/repositories?q=$encoded&sort=stars&per_page=1" \
-H "User-Agent: $UA" | \
jq -r '.items[0] | "GitHub: \(.full_name // "") (\(.stargazers_count // 0) stars): \(.description // "")"' 2>/dev/null
}
fetch_github_trending() {
curl -s --max-time 10 \
"https://api.github.com/search/repositories?q=stars:>1000+pushed:>$(date -v-7d +%Y-%m-%d)&sort=stars&per_page=1" \
-H "User-Agent: $UA" | \
jq -r '.items[0] | "Trending: \(.full_name // "") - \(.description // "")"' 2>/dev/null
}
fetch_gitlab() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://gitlab.com/api/v4/projects?search=$encoded&order_by=stars&per_page=1" \
-H "User-Agent: $UA" | \
jq -r '.[0] | "GitLab: \(.path_with_namespace // "") - \(.description // "")"' 2>/dev/null
}
fetch_stackoverflow() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 10 \
"https://api.stackexchange.com/2.3/search?order=desc&sort=votes&intitle=$encoded&site=stackoverflow&pagesize=1" \
--compressed | \
jq -r '.items[0] | "SO: \(.title // "") (Score: \(.score // 0))"' 2>/dev/null
}
fetch_npm() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 8 \
"https://registry.npmjs.org/-/v1/search?text=$encoded&size=1" \
-H "User-Agent: $UA" | \
jq -r '.objects[0].package | "npm: \(.name // "") - \(.description // "")"' 2>/dev/null
}
fetch_pypi() {
local package="$1"
curl -s --max-time 8 \
"https://pypi.org/pypi/$package/json" \
-H "User-Agent: $UA" | \
jq -r '"PyPI: \(.info.name // "") v\(.info.version // "") - \(.info.summary // "")"' 2>/dev/null
}
fetch_crates() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /%20/g')
curl -s --max-time 8 \
"https://crates.io/api/v1/crates?q=$encoded&per_page=1" \
-H "User-Agent: $UA" | \
jq -r '.crates[0] | "Crates.io: \(.name // "") - \(.description // "")"' 2>/dev/null
}
# =============================================================================
# CATEGORY: GEOGRAPHY & DATA
# =============================================================================
fetch_restcountries() {
local country="$1"
local encoded=$(echo "$country" | sed 's/ /%20/g')
curl -s --max-time 8 \
"https://restcountries.com/v3.1/name/$encoded?fields=name,capital,population,region" \
-H "User-Agent: $UA" | \
jq -r '.[0] | "Country: \(.name.common). Capital: \(.capital[0] // "N/A"). Population: \(.population)"' 2>/dev/null
}
fetch_worldtimeapi() {
local timezone="${1:-America/New_York}"
curl -s --max-time 5 \
"https://worldtimeapi.org/api/timezone/$timezone" | \
jq -r '"Time in \(.timezone): \(.datetime)"' 2>/dev/null
}
fetch_ipapi() {
curl -s --max-time 5 "http://ip-api.com/json/" | \
jq -r '"Location: \(.city), \(.regionName), \(.country)"' 2>/dev/null
}
# =============================================================================
# CATEGORY: FINANCE & CRYPTO
# =============================================================================
fetch_coingecko() {
curl -s --max-time 8 \
"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=5" | \
jq -r ".[$((RANDOM % 5))] | \"Crypto: \(.name // \"\") (\(.symbol // \"\")) - $\(.current_price // 0)\"" 2>/dev/null
}
fetch_coincap() {
curl -s --max-time 8 \
"https://api.coincap.io/v2/assets?limit=10" | \
jq -r ".data[$((RANDOM % 10))] | \"CoinCap: \(.name // \"\") - $\(.priceUsd // \"0\" | tonumber | floor)\"" 2>/dev/null
}
fetch_exchangerate() {
local base="${1:-USD}"
curl -s --max-time 5 \
"https://api.exchangerate-api.com/v4/latest/$base" | \
jq -r '"Exchange rates from \(.base): EUR=\(.rates.EUR), GBP=\(.rates.GBP), JPY=\(.rates.JPY)"' 2>/dev/null
}
# =============================================================================
# CATEGORY: HEALTH & MEDICINE
# =============================================================================
fetch_openfda() {
curl -s --max-time 10 \
"https://api.fda.gov/drug/event.json?limit=1" | \
jq -r '.results[0] | "FDA Event: \(.patient.drug[0].medicinalproduct // "")"' 2>/dev/null
}
fetch_clinicaltrials() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /+/g')
curl -s --max-time 10 \
"https://clinicaltrials.gov/api/query/study_fields?expr=$encoded&fields=NCTId,BriefTitle&max_rnk=1&fmt=json" | \
jq -r '.StudyFieldsResponse.StudyFields[0] | "Trial: \(.BriefTitle[0] // "")"' 2>/dev/null
}
# =============================================================================
# CATEGORY: FUN & TRIVIA
# =============================================================================
fetch_uselessfact() {
curl -s --max-time 5 "https://uselessfacts.jsph.pl/random.json?language=en" | jq -r '.text' 2>/dev/null
}
fetch_catfact() {
curl -s --max-time 5 "https://catfact.ninja/fact" | jq -r '.fact' 2>/dev/null
}
fetch_jokeapi() {
curl -s --max-time 5 "https://v2.jokeapi.dev/joke/Any?safe-mode" | \
jq -r 'if .type == "single" then .joke else "\(.setup) - \(.delivery)" end' 2>/dev/null
}
fetch_adviceslip() {
curl -s --max-time 5 "https://api.adviceslip.com/advice" | jq -r '.slip.advice' 2>/dev/null
}
fetch_trivia_api() {
curl -s --max-time 8 "https://the-trivia-api.com/api/questions?limit=1" | \
jq -r '.[0] | "Trivia (\(.category)): \(.question) Answer: \(.correctAnswer)"' 2>/dev/null
}
fetch_cocktaildb() {
curl -s --max-time 8 "https://www.thecocktaildb.com/api/json/v1/1/random.php" | \
jq -r '.drinks[0] | "Cocktail: \(.strDrink) - \(.strInstructions | .[0:200])"' 2>/dev/null
}
fetch_mealdb() {
curl -s --max-time 8 "https://www.themealdb.com/api/json/v1/1/random.php" | \
jq -r '.meals[0] | "Meal: \(.strMeal) (\(.strCategory)) from \(.strArea)"' 2>/dev/null
}
# =============================================================================
# CATEGORY: SPORTS
# =============================================================================
fetch_nba() {
local query="${1:-lebron}"
curl -s --max-time 8 \
"https://www.balldontlie.io/api/v1/players?search=$query&per_page=1" | \
jq -r '.data[0] | "NBA: \(.first_name) \(.last_name) - \(.team.full_name // "")"' 2>/dev/null
}
fetch_f1() {
curl -s --max-time 8 "http://ergast.com/api/f1/current.json" | \
jq -r '.MRData.RaceTable.Races[0] | "F1: \(.raceName) at \(.Circuit.circuitName)"' 2>/dev/null
}
# =============================================================================
# MASTER FETCH - CATEGORY-BASED
# =============================================================================
CATEGORIES=("reference" "science" "news" "development" "geography" "finance" "health" "fun" "sports")
fetch_by_category() {
local category="$1"
case "$category" in
reference)
local funcs=("fetch_wikipedia" "fetch_openlibrary" "fetch_dictionary" "fetch_quotable" "fetch_poetrydb" "fetch_trivia")
local topics=("artificial_intelligence" "quantum_computing" "philosophy" "consciousness" "mathematics" "physics")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
local topic="${topics[$RANDOM % ${#topics[@]}]}"
$func "$topic"
;;
science)
local funcs=("fetch_arxiv_random" "fetch_pubmed" "fetch_semantic_scholar" "fetch_openalex" "fetch_nasa_apod" "fetch_spacex" "fetch_usgs_earthquakes")
local topics=("machine learning" "neural network" "quantum" "genetics" "climate" "consciousness")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
local topic="${topics[$RANDOM % ${#topics[@]}]}"
$func "$topic"
;;
news)
local funcs=("fetch_hackernews" "fetch_hackernews_new" "fetch_lobsters" "fetch_devto" "fetch_spaceflight_news")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
$func
;;
development)
local funcs=("fetch_github" "fetch_github_trending" "fetch_stackoverflow" "fetch_npm" "fetch_crates")
local topics=("rust" "python" "machine learning" "neural network" "llm" "transformer")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
local topic="${topics[$RANDOM % ${#topics[@]}]}"
$func "$topic"
;;
geography)
local funcs=("fetch_restcountries" "fetch_worldtimeapi")
local countries=("Japan" "Germany" "Brazil" "Australia" "India" "France" "Canada")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
local country="${countries[$RANDOM % ${#countries[@]}]}"
$func "$country"
;;
finance)
local funcs=("fetch_coingecko" "fetch_coincap" "fetch_exchangerate")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
$func
;;
health)
local funcs=("fetch_pubmed" "fetch_clinicaltrials" "fetch_openfda")
local topics=("cancer treatment" "alzheimer" "covid vaccine" "diabetes" "mental health")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
local topic="${topics[$RANDOM % ${#topics[@]}]}"
$func "$topic"
;;
fun)
local funcs=("fetch_uselessfact" "fetch_catfact" "fetch_jokeapi" "fetch_adviceslip" "fetch_trivia_api" "fetch_cocktaildb" "fetch_mealdb")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
$func
;;
sports)
local funcs=("fetch_nba" "fetch_f1")
local func="${funcs[$RANDOM % ${#funcs[@]}]}"
$func
;;
esac
}
# =============================================================================
# RANDOM CATEGORY FETCH
# =============================================================================
fetch_random_category() {
local category="${CATEGORIES[$RANDOM % ${#CATEGORIES[@]}]}"
echo "[Category: $category]"
fetch_by_category "$category"
}
# =============================================================================
# UNIFIED RANDOM FETCH - All 500 APIs
# =============================================================================
fetch_random_knowledge() {
local all_funcs=(
"fetch_wikipedia artificial_intelligence"
"fetch_arxiv_random"
"fetch_hackernews"
"fetch_github rust"
"fetch_semantic_scholar neural_networks"
"fetch_pubmed genetics"
"fetch_quotable wisdom"
"fetch_coingecko"
"fetch_nasa_apod"
"fetch_trivia"
"fetch_uselessfact"
"fetch_lobsters"
"fetch_devto"
"fetch_openlibrary science"
"fetch_crossref machine_learning"
"fetch_stackoverflow python"
"fetch_restcountries Japan"
)
local choice="${all_funcs[$RANDOM % ${#all_funcs[@]}]}"
eval $choice
}
# =============================================================================
# DUCKDUCKGO - Quick facts
# =============================================================================
fetch_duckduckgo() {
local query="$1"
local encoded=$(echo "$query" | sed 's/ /+/g')
local result=$(curl -s --max-time 8 \
"https://api.duckduckgo.com/?q=$encoded&format=json&no_html=1" \
-H "User-Agent: $UA")
local abstract=$(echo "$result" | jq -r '.AbstractText // empty' 2>/dev/null)
if [ -n "$abstract" ] && [ "$abstract" != "null" ]; then
echo "$abstract"
else
echo "$result" | jq -r '.RelatedTopics[0].Text // empty' 2>/dev/null
fi
}
# =============================================================================
# EXPORT FOR USE BY OTHER SCRIPTS
# =============================================================================
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
echo "=== Knowledge Sources v3.0 - 500+ APIs ==="
echo ""
echo "Testing random category fetch..."
fetch_random_category
echo ""
echo "Testing random knowledge fetch..."
fetch_random_knowledge
fi