#!/bin/bash # # Simple program to get the info from a page-a-day calendar # # http://page-a-day.com/pad/2003ZENN/01JAN/01/ # # 2002/02/07 - dys site="http://page-a-day.com" auth_url="$site/pub-bin/paduserlogin.pl" cal_url_base="$site/pad/editorial" date=$(date "+%Y/%m/%d") side="front" if [ $# -eq 0 ]; then cat <&2 "Error: Tried getting a side before calendar name set" elif [[ -z $email || -z $password ]]; then echo 1>&2 "Error: Username and password not set" else dir="/tmp/calendar_${cal}_$(date --date=$date +%Y_%m_%d)" [ ! -e "$dir" ] && mkdir "$dir" echo "Writing $cal to: $dir" file="$dir/$side.html" if [ -e "$file" ]; then echo 1>&2 "Skipped: $file already exists" else # If not logged in yet, do so if [ -z $SESSIONID ]; then ID_NAME="PADSID" args="--data rm=setuser --data target_uri= --data email=$email --data password=$password" command="curl --cookie-jar - --output /dev/null --silent $args $auth_url" SESSIONID=$($command | grep $ID_NAME | sed -e "s/^.*$ID_NAME[[:space:]]*/$ID_NAME=/") echo "Got session id: $SESSIONID" fi # Build the appropriate url url_date=$(date --date=$date "+%m%b/%d" | tr [:lower:] [:upper:]) year=$(date --date=$date "+%Y") url="$cal_url_base/$side/$year$cal/$url_date/" echo "Getting url: $url" # Get the page curl --cookie "$SESSIONID" --silent $url --output $file echo "Wrote $cal $side on $date to: $file" # Get any images embedded in the page for image in $(cat "$file" \ | sed -e "s/&2 "Skipped: $imgfile already exists" else imgurl="$url$image" echo "Getting image: $imgurl" curl --cookie "$SESSIONID" --location --referer $url --silent "$imgurl" --output $imgfile echo "Wrote image to: $imgfile" fi done fi fi fi shift done # logout now that it's done if [ ! -z "$SESSIONID" ]; then curl --cookie "$SESSIONID" --output /dev/null --silent $auth_url?rm=logout fi