2022-11-16 16:37:34 +01:00
|
|
|
# post to export-rows endpoint
|
|
|
|
# shellcheck shell=bash disable=SC2154
|
|
|
|
function post_export() {
|
|
|
|
local curloptions
|
2023-01-27 18:04:27 +01:00
|
|
|
for d in "$@"; do
|
|
|
|
curloptions+=("--data-urlencode")
|
|
|
|
curloptions+=("$d")
|
|
|
|
done
|
|
|
|
# support filtering result sets with facets
|
|
|
|
if [[ ${args[--mode]} == "records" ]]; then
|
|
|
|
mode="record-based"
|
|
|
|
else
|
|
|
|
mode="row-based"
|
|
|
|
fi
|
|
|
|
curloptions+=("--data-urlencode")
|
|
|
|
curloptions+=("engine={\"facets\":${args[--facets]},\"mode\":\"${mode}\"}")
|
2023-01-12 11:18:06 +01:00
|
|
|
# support file output
|
2022-11-16 16:37:34 +01:00
|
|
|
if [[ ${args[--output]} ]]; then
|
|
|
|
if ! mkdir -p "$(dirname "${args[--output]}")"; then
|
|
|
|
error "unable to create parent directory for ${args[--output]}"
|
|
|
|
fi
|
2023-01-12 11:18:06 +01:00
|
|
|
curloptions+=("--output" "${args[--output]}")
|
2022-11-16 16:37:34 +01:00
|
|
|
fi
|
2023-01-12 11:18:06 +01:00
|
|
|
# post
|
2024-12-08 23:37:39 +01:00
|
|
|
if ! curl -fs "${curloptions[@]}" "${OPENREFINE_URL}/command/core/export-rows$(get_csrf)"; then
|
2022-11-16 16:37:34 +01:00
|
|
|
error "exporting ${args[project]} failed!"
|
|
|
|
else
|
|
|
|
if [[ ${args[--output]} ]]; then
|
2023-01-27 18:04:27 +01:00
|
|
|
log "exported ${args[project]}" "file: ${args[--output]}" "lines: $(wc -l <"${args[--output]}")"
|
2022-11-16 16:37:34 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|