meili scripting
This commit is contained in:
49
to_meili.sh
Normal file
49
to_meili.sh
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user