Skip to content

Instantly share code, notes, and snippets.

@iraizo
Last active May 14, 2024 13:18
Show Gist options
  • Save iraizo/7b5057e4e83a39874e778246c98502c5 to your computer and use it in GitHub Desktop.
Save iraizo/7b5057e4e83a39874e778246c98502c5 to your computer and use it in GitHub Desktop.
script to add items to jacks autopricer
#!/bin/bash
# Base URL for the auto-pricing system (adjusted for item name after /add/)
BASE_URL="http://127.0.0.1:3456/items/add/"
add_item() {
local item_name="$1"
url=$(printf "%s" "$BASE_URL$(sed 's/ /%20/g' <<< "$1")")
response_code=$(curl -X POST -s -o /dev/null -w "%{http_code}" "$url")
if [[ $response_code -eq 200 ]]; then
echo "Added item: $item_name"
elif [[ $response_code -eq 400 ]]; then
echo "Item '$item_name' already exists."
else
echo "Failed to add item '$item_name' (Status: $response_code)"
fi
}
# Check for user input
if [ -n "$1" ]; then
# User provided an item name as an argument
add_item "$1"
else
# Read items from file (items.txt assumed)
if [ -f items.txt ]; then
while IFS= read -r line; do
add_item "$line"
done < items.txt
echo "Added items from items.txt"
else
echo "No items.txt file found or no item provided as argument."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment