<commit_before>#!/bin/sh
endpoint=$1
start=${2:-1}
end=${3:-100}
shift 3

if [ -z "$endpoint" ]; then
	echo "usage: $0 <endpoint> [start] [end]"
	echo "example: $0 http://127.0.0.1:8880/fortune.db 1 10"
	exit 64
fi

json_escape() {
	python -c 'import sys, json; json.dump(sys.stdin.read(), sys.stdout)'
}

for id in $(seq "$start" "$end"); do
	message="$(fortune | json_escape)"
	data="{\"user\" : \"$USER\", \"postDate\" : \"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\", \"message\" : $message}"
	curl -s -H "Content-Type: application/json" -XPUT "$endpoint/$id" -d "$data" "$@"
done


# Usage Example:
# index_and_get_fortune() {
# 	endpoint=$1
# 	start=${2:-1}
# 	end=${3:-100}
# 	../index_fortune.sh "$endpoint" "$start" "$end" "$@"
# 	sleep 3
# 	for id in $(seq "$start" "$end"); do
# 		curl -s "$endpoint/$id" "$@"
# 	done
# }
# index_and_get_fortune "http://127.0.0.1:8880/test/fortune" 1 10 -H "Accept: application/json; indent=4"
# index_and_get_fortune "http://127.0.0.1:8880/test/fortune" 1 100 -H "Accept: application/msgpack" > /dev/null<commit_msg>index_fortune: added echo to example<commit_after>#!/bin/sh
endpoint=$1
start=${2:-1}
end=${3:-100}
shift 3

if [ -z "$endpoint" ]; then
	echo "usage: $0 <endpoint> [start] [end]"
	echo "example: $0 http://127.0.0.1:8880/fortune.db 1 10"
	exit 64
fi

json_escape() {
	python -c 'import sys, json; json.dump(sys.stdin.read(), sys.stdout)'
}

for id in $(seq "$start" "$end"); do
	message="$(fortune | json_escape)"
	data="{\"user\" : \"$USER\", \"postDate\" : \"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\", \"message\" : $message}"
	curl -s -H "Content-Type: application/json" -XPUT "$endpoint/$id" -d "$data" "$@"
done


# Usage Example:
# index_and_get_fortune() {
# 	endpoint=$1
# 	start=${2:-1}
# 	end=${3:-100}
# 	../index_fortune.sh "$endpoint" "$start" "$end" "$@"
#   echo -n "." >&2
# 	sleep 3
#   echo "." >&2
# 	for id in $(seq "$start" "$end"); do
# 		curl -s "$endpoint/$id" "$@"
# 	done
# }
# index_and_get_fortune "http://127.0.0.1:8880/test/fortune" 1 10 -H "Accept: application/json; indent=4"
# index_and_get_fortune "http://127.0.0.1:8880/test/fortune" 1 100 -H "Accept: application/msgpack" > /dev/null
{'fraction_non_alphanumeric': 0.24861367837338263, 'fraction_numerical': 0.05730129390018484, 'mean_word_length': 3.8871331828442437, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4691668', 'n_tokens_mistral': 987, 'n_tokens_neox': 900, 'n_words': 206}