Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 4247758836" >&2
echo " $0 4125551212 4247758836" >&2
exit 1
command -v curl > /dev/null 2>&1 || { echo "This script requires curl, but it's not installed." 2>&1; exit 1; }
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/'
echo "Unable to retrieve order details. Are your email and order number correct?" >&2
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment