Skip to content

Instantly share code, notes, and snippets.

@DavidWittman
Last active March 21, 2017 22:13
Show Gist options
  • Save DavidWittman/df478223d7cb3164e42f1e947e56af3c to your computer and use it in GitHub Desktop.
Save DavidWittman/df478223d7cb3164e42f1e947e56af3c to your computer and use it in GitHub Desktop.
Scrape the Lenovo order details page and print the estimated arrival date.
#!/usr/bin/env bash
# When will my Lenovo order arrive?
#
# I grew impatient while waiting for my Thinkpad to ship, and the arrival date
# kept changing, so I wrote this script to scrape their order details page.
#
# Might not work on all platforms, and it's parsing HTML with sed, so there be
# plenty of dragons within this script.
if [[ $# -ne 2 ]]; then
echo "usage: $0 <email/phone> <order number>" >&2
echo " ex: $0 [email protected] 4247758836" >&2
echo " $0 4125551212 4247758836" >&2
exit 1
fi
command -v curl > /dev/null 2>&1 || { echo "This script requires curl, but it's not installed." 2>&1; exit 1; }
EMAIL="$1"
ORDER_NUMBER="$2"
URL="https://ovp.lenovo.com/lenovo-ovp/public/showDetail!showPublicOrderDetail.action?orderNumber=${ORDER_NUMBER}&email=${EMAIL}"
HTML=$(curl -s "${URL}")
if echo "$HTML" | grep -q "Order Detail"; then
echo "${HTML}" | tr -d '\n\r\t' | sed -Ee 's/.*tpb_bar_pn_date_box.*text-align:right;">([^<]+).*/\1/'
else
echo "Unable to retrieve order details. Are your email and order number correct?" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment