<commit_before>#!/bin/bash



if [ "$#" -ne 3 ]; then
  echo "Wrong number of arguments!"
  echo "Usage: $ lookup_shipment.sh <tracking_number> <env> <auth_token>" >&2
  exit 1
fi

tracking_number=$1
auth_token=$3

# Helper functions
script_help() {
  cat <<- EOM
Usage:
./lookup_shipment.sh <tracking_number> <env> <auth_token>

Options:
----------------
<tracking_number>
<environment>	"production" or "staging"			
<auth_token>  	API key
----------------
EOM
exit
}

# Check env
if [[ $2 == 'production' ]]; then
  url='api.thepublicrad.io';
  headers="Authorization: Bearer $auth_token";
elif [[ $2 == 'staging' ]]; then
  url='api-staging.thepublicrad.io';
  headers="Authorization: Bearer $auth_token";
else
  script_help
fi

# get the shipment, shipment_id and order_id
shipment=$(curl -s -H "$headers" $url/shipments?tracking_number=$tracking_number \
	| jq -c '[.data | {id: .id, order_id: .order_id}][]')
shipment_id=$(echo -n $shipment | jq '.id')
order_id=$(echo -n $shipment | jq '.order_id')


# get all of the order info. strip the quotes off.
order=$(curl -s -H "$headers" $url/orders/$order_id)
name=$(echo -n $order | jq '.name')
name=$(eval echo $name)
street_address_1=$(echo -n $order | jq '.street_address_1')
street_address_1=$(eval echo $street_address_1)
street_address_2=$(echo -n $order | jq '.street_address_2')
street_address_2=$(eval echo $street_address_2)
city=$(echo -n $order | jq '.city')
city=$(eval echo $city)
state=$(echo -n $order | jq '.state')
state=$(eval echo $state)
postal_code=$(echo -n $order | jq '.postal_code')
postal_code=$(eval echo $postal_code)
order_source=$(echo -n $order | jq '.order_source')
order_source=$(eval echo $order_source)
reference_number=$(echo -n $shipment | jq '.reference_number')
comments=$(echo -n $shipment | jq '.comments')

if [ -z "$street_address_2"  ]; then
	$street_address_2=$" "
fi

echo "street_address_2 is" $street_address_2

# get the radios in the shipment, put the frequencies in an array
radios=($(curl -s -H "$headers" $url/shipments/$shipment_id/radios | jq -c '[.data[] | .frequency][]' | sed 's/"//g'))
# get the number of radios in the shipment, for good measure
radio_count=${#radios[@]}
echo "radio_count is" $radio_count


# create order info image
if [ -z "$comments" ]; then
   convert -pointsize 32 -font /usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf \
	-size 601.5x864 caption:'To:\n'"$name"'\n'"$street_address_1"'\n'"$street_address_2"'\n'"$city"', '"$state"'\n'"$postal_code"'\n\nOrder no:\n'"$order_no" \
	/home/pi/ops_tools/temp/order_info.png
else
	convert -pointsize 32 -font /usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf \
	-size 601.5x864 caption:'To:\n'"$name"'\n'"$street_address_1"'\n'"$street_address_2"'\n'"$city"', '"$state"'\n'"$postal_code"'\n\nOrder no:\n'"$order_no"'\n\nMessage:\n'"$comments" \
	/home/pi/ops_tools/temp/order_info.png
fi

# debug - print just the order info
#lpr -P DYMO_LabelWriter_450_Turbo /home/pi/ops_tools/temp/order_info.png

# merge order_info into background
convert /home/pi/ops_tools/data/uncommongoods_background.png /home/pi/ops_tools/temp/order_info.png \<commit_msg>again<commit_after>#!/bin/bash



if [ "$#" -ne 3 ]; then
  echo "Wrong number of arguments!"
  echo "Usage: $ lookup_shipment.sh <tracking_number> <env> <auth_token>" >&2
  exit 1
fi

tracking_number=$1
auth_token=$3

# Helper functions
script_help() {
  cat <<- EOM
Usage:
./lookup_shipment.sh <tracking_number> <env> <auth_token>

Options:
----------------
<tracking_number>
<environment>	"production" or "staging"			
<auth_token>  	API key
----------------
EOM
exit
}

# Check env
if [[ $2 == 'production' ]]; then
  url='api.thepublicrad.io';
  headers="Authorization: Bearer $auth_token";
elif [[ $2 == 'staging' ]]; then
  url='api-staging.thepublicrad.io';
  headers="Authorization: Bearer $auth_token";
else
  script_help
fi

# get the shipment, shipment_id and order_id
shipment=$(curl -s -H "$headers" $url/shipments?tracking_number=$tracking_number \
	| jq -c '[.data | {id: .id, order_id: .order_id}][]')
shipment_id=$(echo -n $shipment | jq '.id')
order_id=$(echo -n $shipment | jq '.order_id')


# get all of the order info. strip the quotes off.
order=$(curl -s -H "$headers" $url/orders/$order_id)
name=$(echo -n $order | jq '.name')
name=$(eval echo $name)
street_address_1=$(echo -n $order | jq '.street_address_1')
street_address_1=$(eval echo $street_address_1)
street_address_2=$(echo -n $order | jq '.street_address_2')
street_address_2=$(eval echo $street_address_2)
city=$(echo -n $order | jq '.city')
city=$(eval echo $city)
state=$(echo -n $order | jq '.state')
state=$(eval echo $state)
postal_code=$(echo -n $order | jq '.postal_code')
postal_code=$(eval echo $postal_code)
order_source=$(echo -n $order | jq '.order_source')
order_source=$(eval echo $order_source)
reference_number=$(echo -n $shipment | jq '.reference_number')
comments=$(echo -n $shipment | jq '.comments')

if [ -z "$street_address_2" ]; then
	echo "$street_address has zero length"
	$street_address_2=$" "
fi

echo "street_address_2 is" $street_address_2

# get the radios in the shipment, put the frequencies in an array
radios=($(curl -s -H "$headers" $url/shipments/$shipment_id/radios | jq -c '[.data[] | .frequency][]' | sed 's/"//g'))
# get the number of radios in the shipment, for good measure
radio_count=${#radios[@]}
#echo "radio_count is" $radio_count


# create order info image
if [ -z "$comments" ]; then
   convert -pointsize 32 -font /usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf \
	-size 601.5x864 caption:'To:\n'"$name"'\n'"$street_address_1"'\n'"$street_address_2"'\n'"$city"', '"$state"'\n'"$postal_code"'\n\nOrder no:\n'"$order_no" \
	/home/pi/ops_tools/temp/order_info.png
else
	convert -pointsize 32 -font /usr/share/fonts/truetype/msttcorefonts/Courier_New_Bold.ttf \
	-size 601.5x864 caption:'To:\n'"$name"'\n'"$street_address_1"'\n'"$street_address_2"'\n'"$city"', '"$state"'\n'"$postal_code"'\n\nOrder no:\n'"$order_no"'\n\nMessage:\n'"$comments" \
	/home/pi/ops_tools/temp/order_info.png
fi

# debug - print just the order info
#lpr -P DYMO_LabelWriter_450_Turbo /home/pi/ops_tools/temp/order_info.png

# merge order_info into background
convert /home/pi/ops_tools/data/uncommongoods_background.png /home/pi/ops_tools/temp/order_info.png \
{'fraction_non_alphanumeric': 0.18250710451531418, 'fraction_numerical': 0.013893274392169246, 'mean_word_length': 4.780109489051095, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2172981', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2354, 'n_words': 547}