#!/bin/bash

# KOMPAS ePaper Downloader
# Created by Sugeng Doyle, Modified by Utian Ayuba

# Now, it's just download today's KOMPAS ePaper .jpg direct link

# Today's Date
TGL=`date +%d-%b-%Y`

# Make a directory based on today's date
mkdir -p $TGL

# Major URL
URL="http://images.cdn.realviewdigital.com/rvimageserver/Kompas/Kompas/"

# Download first page
echo "Downloading first page of KOMPAS ePaper date $TGL..."
wget -nvc -P $TGL $URL$TGL"/page0000001.jpg"

# Open first page using firefox
echo "Opening first page using Mozilla Firefox..."
firefox $TGL"/page0000001.jpg" &

# Input the numbers of page
echo -n "Please check the numbers of page on the first page and input here: "
read PAGE

# Download from second page
echo "Downloading KOMPAS ePaper date $TGL from page #2 until page #$PAGE..."
CHAP=2

until [ $CHAP -gt $PAGE ]; do
	
	if [ ${#CHAP} == 1 ]; then
		CH="00"$CHAP
	else if [ ${#CHAP} == 2 ]; then
		CH="0"$CHAP
	else CH=$CHAP
	fi
	fi

	wget -nvc -P $TGL $URL$TGL"/""page0000"$CH".jpg"
	
	let CHAP+=1
done

echo "Download completed. The KOMPAS ePaper is save to $TGL directory."

exit;

