meili scripting

This commit is contained in:
Bel LaPointe
2021-12-15 15:35:30 -07:00
parent 1e39a34c54
commit b3d26a88c2
4 changed files with 54 additions and 3 deletions

49
to_meili.sh Normal file
View File

@@ -0,0 +1,49 @@
#! /bin/bash
export MEILI="${MEILI:-"127.0.0.1:7700"}"
export SCRAPED="${SCRAPED:-"./scraped"}"
curl() {
$(which curl) -Ss -L -H 'Content-Type: application/json' "$@"
echo
}
log() {
echo "> $(date) > $*" >&2
}
meili_index() {
log index
curl "$MEILI"/indexes/scraped
}
meili_query() {
log query: "$*"
curl "$MEILI"/indexes/scraped/search -X POST -d "$(goprintf '{%q: %q}' "q" "$*")"
}
meili_queue() {
log queue
curl "$MEILI"/indexes/scraped/updates
}
scraped_to_meili() {
find "$SCRAPED" -type f \
| sort \
| while read -r md_path; do
id="$(echo "$md_path" | sed 's/[^a-zA-Z0-9_-]/_/g')"
content="$(cat "$md_path")"
echo md_path=$md_path, content=${#content}
curl -sS \
"$MEILI"/indexes/scraped/documents \
-X POST \
-d "$(
goprintf '[{%q: %q, %q: %q}]' \
"id" \
"$id" \
"content" \
"$content"
)"
break
done
}