Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Bash script that downloads 90s publications of CGW into a tar archive, compresses when the script finishes.
#!/bin/bash
# Script to download every 90s publication of
# Computer Gaming World into an archive and
# compress it. Changes the file names to m-year
# to make it easier to match game release dates to
# the magazine.
# It takes a while. It's a lot of PDFs.
# If you have to stop halfway through a download,
# ctrl+c, don't rm anything, run it again, and it
# will start where you left off.
# For wgetting everything
BASEURL="http://www.cgwmuseum.org/galleries/issues/cgw_"
last=185
if [ -e cgw*pdf ]; then
echo "Found a pdf! Starting where you left off."
first="$(find cgw*pdf | cut -d'_' -f 2 | cut -d'.' -f 1)"
rm cgw*pdf
else
first=67
# README
echo "Computer Gaming World Magazine: 90s Issues" > README.md
echo "==========================================" >> README.md
echo "This is an archive of all CGW publications from 1990 to 1999" >> README.md
tar -cf cgw_archive.tar README.md && rm README.md
fi
# For changing the name to calendar m-year.pdf
month=$(( ( $first+6 )%12 ))
# Issue 73 messes up the order bc it's a Jul-Aug issue
if [ $first -gt 73 ]; then
month=$((1+month));
val=67
else
val=66
fi
year=$(( 1990+( $first-$val )/12 ))
# wget away
echo "Starting..."
for i in `seq $first $last`;
do
# Download issue, change name to m-year, add to archive
echo "Downloading issue $month-$year.pdf..."
wget "$BASEURL$i.pdf" &&
mv "cgw_$i.pdf" "$month-$year.pdf" &&
tar -r -f cgw_archive.tar "$month-$year.pdf" &&
rm "$month-$year.pdf"
echo "$month-$year.pdf has been archived."
# Increment
if [ $i -eq 73 ]; then # Jul-Aug issue again
month=$((2+$month))
elif [ $month -eq 12 ]; then
month=1
year=$((1+$year))
else
month=$((1+$month))
fi
done
# Compress
gzip cgw_archive.tar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment