#!/bin/ksh # Usage: getcomix.ksh [ -c n ] # # where n is the number of days' worth of comix (counting # backwards from the current date) you wish to view. # NOTE: -c does not cross month boundaries. If you want to # view three days' worth of comix on the first of the month, # you'll have to copy the script to a temporary file and # modify THISDAY and THISMONTH manually. # # wget, lynx and xv are assumed to work and be in the PATH. #unset http_proxy GETDATE="" PATH=$PATH:/opt/gnu/bin:/opt/sfw/bin:/usr/sfw/bin # Just to be sure TMPDIR=~/pix COMICS="ad bt db ft fu mb td tmhel luc tm tmcat ba be bo pr ss tmloo nq cle poc hc wes tmhou prc" UMCREATORS='' UMWASH='' UMCOMIX="arlonjanis dilbert getfuzzy bignate luann forbetter pibgorn chickweed peanuts soup2nutz sheldon barkeaterlake frazz brevity" RBMACOMIX="Baby_Blues Bizarro Blondie Crankshaft Family_Circus Funky_Winkerbean Lockhorns Mallard_Fillmore Mutts Piranha Sally_Forth 6Chix Mgoose Zippy_the_Pinhead Zits Fast_Track" CHRONCOMIX="9_Chickweed_Lane BC Baldo Ballard_Street Boffo Boondocks Cathy Cleats Dilbert Dinette_Set Doonesbury Drabble For_Better_Or_Worse Foxtrot Fred_Basset Fuzzy Heart Jumble Kudzu La_Cucaracha Luann Monty Non_Sequitur_pan One_Big_Happy Peanutsb Pearls_Before_Swine Preteena Rhymes_with_Orange Rose Rubes Safe_Havens Shermans_Lagoon Shoe Speed_Bump Tank_McNamara Willy_n_Ethel Wizard_of_Id" YEAR=$(date +%Y) SHORTYEAR=$(date +%y) COUNT=0 NUMDAYS=1 NOHUP='' # Set up days in month set -A DAYS_IN_MONTH 0 31 28 31 30 31 30 31 31 30 31 30 31 # Set up leap year # Note that this is not Y2100 compliant code YEAR_DIV_4=$(($YEAR / 4)) if [[ $((YEAR_DIV_4 * 4)) -eq $YEAR ]] then DAYS_IN_MONTH[2]=29 fi function strip_leading_zeroes { # Kludge to keep, e.g., 08, from being interpreted as octal in # IN_MONTH and IN_DAY if [[ IN_MONTH -lt 10 ]] then IN_MONTH=$(print $IN_MONTH | /bin/cut -c2) fi if [[ IN_DAY -lt 10 ]] then IN_DAY=$(print $IN_DAY | /bin/cut -c2) fi } function normalize_date { IN_STR=$1 IN_MONTH=$(print $IN_STR | cut -c1-2) IN_DAY=$(print $IN_STR | cut -c3-4) # strip leading zeroes OUT_MONTH=$((IN_MONTH + 0)) OUT_DAY=$((IN_DAY + 0)) NORMAL_DATE="$YEAR/$OUT_MONTH/$OUT_DAY" } function daysoff { IN_DATE=$1 DAYS_OFF=$2 IN_MONTH=$(print $IN_DATE | /bin/cut -c1-2) IN_DAY=$(print $IN_DATE | /bin/cut -c3-4) strip_leading_zeroes # echo DEBUG In daysoff: IN_DATE = $IN_DATE # echo DAYS_OFF = $DAYS_OFF # echo IN_MONTH = $IN_MONTH # echo IN_DAY = $IN_DAY if [[ $IN_DAY -gt $DAYS_OFF ]] # It's not early in the month -- simple case then OUT_DAY=$((IN_DAY - DAYS_OFF)) OUT_MONTH=$IN_MONTH RESULT=$(printf "%02d%02d" $OUT_MONTH $OUT_DAY) return fi if [[ $IN_MONTH -gt 1 ]] # It's not January then OUT_MONTH=$(($IN_MONTH - 1)) OUT_DAY_TEMP=$(($IN_DAY + ${DAYS_IN_MONTH[$OUT_MONTH]})) OUT_DAY=$(($OUT_DAY_TEMP - $DAYS_OFF)) RESULT=$(printf "%02d%02d" $OUT_MONTH $OUT_DAY) return fi if [[ $IN_MONTH -eq 1 ]] # It's January, too early in the month then print "ERROR: Cannot cross year boundaries" return fi print "ERROR: impossible case in function daysoff, probably a month problem" } function getdate { THISDAY=$(date +%d) THISMONTH=$(date +%m) # Remove leading zeroes -- if not, printf interprets them as octal numbers. THISDAY=$((THISDAY + 0)) THISMONTH=$((THISMONTH + 0)) NEWDATE=$(printf "%02d%02d" $THISMONTH $THISDAY) while [[ $NUMDAYS -gt 0 ]] do GETDATE="$NEWDATE $GETDATE" daysoff $NEWDATE 1 NEWDATE=$RESULT NUMDAYS=$((NUMDAYS - 1)) done if [[ -z $GETDATE ]] then GETDATE=$(printf "%02d%02d" $THISMONTH $THISDAY) print GETDATE is $GETDATE fi } function loadshare { SUBPROCESSES=$(/usr/bin/ptree $$ | /bin/wc -l) if [[ $SUBPROCESSES -gt 100 ]] then echo $SUBPROCESSES subprocesses found ... sleeping $SLEEPSECS seconds SLEEPSECS=$((SUBPROCESSES / 100)) sleep $SLEEPSECS # else # echo DEBUG $SUBPROCESSES subprocesses found fi } # usage: getups -c # getups [ MMDD [ MMDD ... ] ] # # where is a count backwards from the current date (including the # current date -- current month only) and MMDD [MMDD ...] is a list of # dates with leading zeroes. If omitted, todays date is the default. mkdir $TMPDIR 2>/dev/null cd $TMPDIR while getopts :c: opt do case $opt in c) COUNT=1 NUMDAYS=$OPTARG ;; \?) print "usage: getups -c n" print " getups \[ MMDD \[ MMDD ... \] \] " return 1 esac done shift $(($OPTIND - 1)) TENTATIVEDATES=$* getdate # First, get UPS comix: for STRIP in $COMICS do for ISSUE in $GETDATE do $NOHUP lynx --dump "http://images.ucomics.com/comics/$STRIP/$YEAR/$STRIP$SHORTYEAR$ISSUE.gif" > $STRIP$SHORTYEAR$ISSUE.gif & print GETTING $STRIP$SHORTYEAR$ISSUE.gif loadshare done done # Now get RBMA comics for STRIP in $RBMACOMIX do for ISSUE in $GETDATE do $NOHUP wget -q --referer=http://www.chron.com --output-document=0$STRIP$SHORTYEAR$ISSUE.gif http://cst.rbma.com/content/$STRIP?date=$YEAR$ISSUE & print GETTING $STRIP$SHORTYEAR$ISSUE.gif loadshare done done # Next, get UM comix: for STRIP in $UMCOMIX do for ISSUE in $GETDATE do ISSUE="$YEAR$ISSUE" # First, grab the line containing the name of the comic $NOHUP lynx -source "http://www.unitedmedia.com/comics/$STRIP/archive/$STRIP-$ISSUE.html" | grep -i " $STRIP.line # Next, change everything up to .../comics/$STRIP into URL format # (preserving the rest as the filename) sed "s@^.*=\"/comics/$STRIP@http://www.unitedmedia.com/comics/$STRIP@" < $STRIP.line > $STRIP.line2 # Finally, eliminate everything after ".gif" or ".jpg" -- what's left is the URL grep '\.gif' $STRIP.line2 >/dev/null 2>&1 if [[ $? -eq 0 ]] then sed 's@\.gif\".*$@.gif@' < $STRIP.line2 > $STRIP.url else sed 's@\.jpg\".*$@.jpg@' < $STRIP.line2 > $STRIP.url fi # Now actually get it. print GETTING $STRIP$ISSUE.gif $NOHUP lynx -source $(cat $STRIP.url) > $STRIP$ISSUE.gif & loadshare done done # UM Creators strip(s) for STRIP in $UMCREATORS do for ISSUE in $GETDATE do daysoff $ISSUE 7 OLDISSUE=$YEAR$RESULT lynx -source "http://www.unitedmedia.com/creators/$STRIP/archive/$STRIP-$OLDISSUE.html" | grep " $STRIP.line sed "s@^.* $STRIP.line2 sed 's@\.gif\" BORD.*$@.gif@' < $STRIP.line2 > $STRIP.url print GETTING $STRIP$OLDISSUE.gif $NOHUP lynx -source $(cat $STRIP.url) > $STRIP$OLDISSUE.gif & loadshare done done # UM Washington Post Writers Group strip(s) for STRIP in $UMWASH do for ISSUE in $GETDATE do daysoff $ISSUE 7 OLDISSUE=$YEAR$RESULT # print DEBUG "http://www.unitedmedia.com/wash/$STRIP/archive/$STRIP-$OLDISSUE.html" # lynx -source "http://www.unitedmedia.com/wash/$STRIP/archive/$STRIP-$OLDISSUE.html" > $STRIP-$OLDISSUE.html lynx -source "http://www.unitedmedia.com/wash/$STRIP/archive/$STRIP-$OLDISSUE.html" | grep " $STRIP.line sed "s@^.* $STRIP.line2 sed 's@\.gif\" BORD.*$@.gif@' < $STRIP.line2 > $STRIP.url print GETTING $STRIP$OLDISSUE.gif $NOHUP lynx -source $(cat $STRIP.url) > $STRIP$OLDISSUE.gif & loadshare done done # Finally, get the ones direct from Chron for ISSUE in $GETDATE do normalize_date $ISSUE # lynx -source "http://www.chron.com/content/chronicle/comics/archive/buildcp.hts?v=3.0&page=1&quality=high&cpp=80&c=19&c=2&c=101&c=75&c=84&c=85&c=32&c=104&c=12&c=13&c=43&c=74&c=109&c=27&c=44&c=110&c=18&c=38&c=49&c=112&c=71&c=31&c=117&c=28&c=118&c=83&c=121&c=37&c=1&c=72&c=124&c=67&c=129&c=4&c=147&c=30&c=122&c=46&c=137&c=134&c=153&c=154&c=155&c=87&c=82&c=63&c=86&c=136&c=33&c=128&c=135&c=78&c=90&date=$NORMAL_DATE" > chronsource.txt lynx -source "http://www.chron.com/content/chronicle/comics/archive/buildcp.mpl?v=3.0&page=1&quality=high&cpp=80&c=19&c=2&c=101&c=75&c=84&c=153&c=104&c=12&c=85&c=13&c=82&c=154&c=74&c=90&c=27&c=44&c=110&c=111&c=18&c=38&c=49&c=112&c=71&c=68&c=63&c=31&c=86&c=117&c=28&c=118&c=78&c=155&c=121&c=37&c=1&c=152&c=72&c=87&c=124&c=79&c=136&c=67&c=33&c=128&c=129&c=135&c=4&c=147&c=53&c=30&c=77&c=46&c=137&c=134" > chronsource.txt grep '^ chronlines.txt for STRIP in $CHRONCOMIX do grep $STRIP chronlines.txt | sed "s@^ ascii.files 2>/dev/null awk -F: '{print $1}' ascii.files | while read a do print Renaming $a /bin/mv $a $a.ASCII done # Now rename the zero length files, if any for a in *.[gG][iI][fF] *.[jJ][pP][gG] do if [[ -a $a && ! -s $a ]] then print Renaming zero-length file $a /bin/mv $a $a.ZERO fi done #VIEW='' # #ls *.[gG][iI][fF] >/dev/null 2>&1 #if [[ $? -eq 0 ]] #then # VIEW='*.[gG][iI][fF]' #fi # #ls *.[jJ][pP][gG] >/dev/null 2>&1 #if [[ $? -eq 0 ]] #then # VIEW="$VIEW *.[jJ][pP][gG]" #fi # #print #print -n Viewing files ... # #xv $VIEW print print done. cd $OLDPWD #print "REMOVING $TMPDIR" #sleep 5 #/bin/rm -r $TMPDIR print "REMOVING extraneous files" #sleep 5 /bin/rm -f $TMPDIR/*.ZERO $TMPDIR/*.ASCII $TMPDIR/chron*.txt $TMPDIR/*.url $TMPDIR/*.line $TMPDIR/*.line2 $TMPDIR/ascii*