Skip to content

Instantly share code, notes, and snippets.

@josejuansanchez
Created June 3, 2015 11:36
Show Gist options
  • Save josejuansanchez/a49735fd06a1b6ba8012 to your computer and use it in GitHub Desktop.
Save josejuansanchez/a49735fd06a1b6ba8012 to your computer and use it in GitHub Desktop.
Bash script to download images from the Helioviewer server. http://helioviewer.nascom.nasa.gov
#!/bin/bash
set -x
# Set the directory to store the images
IMAGES_DIRECTORY=images
if [ ! -d "${IMAGES_DIRECTORY}" ]; then
echo "Creando nuevo directorio: ${IMAGES_DIRECTORY}"
mkdir -p ${IMAGES_DIRECTORY}
fi
# Set the source
URL=http://helioviewer.nascom.nasa.gov/jp2/AIA/171/2012/05/01/
# Get the list of images
lns=$(curl -s ${URL} | sed 's/.*href="\([^"]*\)".*/\1/' | grep ".jp2" | tail -n +4)
total=$(echo ${lns} | wc -w)
n=1
# Convert the list into an array
arr=($lns)
# Download the images
for (( i=1; i<=total; i++ ))
do
echo "Downloading $i/$total..."
wget ${URL}${arr[((i-1))]}
num=`printf "%04d" $i`
mv ${arr[((i-1))]} ${IMAGES_DIRECTORY}/$num.jp2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment