Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/sales.git
#!/bin/bash

scrape() {
  local SCRIPT_DIR=$1
  local SUBSCRIBER_DIR=$2
  local POSTAL_CODE=$3

  # 1. Convert the first letter of the postal code to upper case.
  POSTAL_CODE=${3:0:1}
  POSTAL_CODE="${POSTAL_CODE^^}"

  # 2. Convert the postal code into a region recognised by Costco.
  case "$POSTAL_CODE" in
    A) REGION=nl ;;
    B) REGION=ns ;;
    C) REGION=pe ;;
    E) REGION=nb ;;
    G) REGION=qb ;;
    H) REGION=qb ;;
    J) REGION=qb ;;
    K) REGION=on ;;
    L) REGION=on ;;
    M) REGION=on ;;
    N) REGION=on ;;
    P) REGION=on ;;
    R) REGION=mb ;;
    S) REGION=sk ;;
    T) REGION=ab ;;
    V) REGION=bc ;;
    X) REGION=nw ;;
    Y) REGION=yt ;;
    *) REGION=bc ;;
  esac

  # 3. Use the region to get the savings URL.
  URL="http://www.costco.ca/warehouse-instant-savings-${REGION}.html"

  # 3. Dump the data.
  lynx -nolist -nolog -accept_all_cookies -dump -width=2048 \
    -useragent="Mozilla/5.0 Lynx" $URL
}