- tjones
- May 13, 2005
-
|
Quoted below is a simple bash script that will parse the main APOD page and attempt to download any linked image matching the regex. Curl required. Cheers.
code:#!/bin/bash
apod_url="https://apod.nasa.gov/apod/"
apod_out="response.out"
image_name="apod"
echo "Requesting URL: $apod_url"
response="$(curl -s $apod_url)"
echo "Writing response to file: $apod_out"
echo "$response" > $apod_out
#response="$(<$apod_out)"
image_file="$(sed -n '1,//s/.*href=\"\(image.\+\..\{3\}\)\">/\1/p' <<< $response)"
echo "Image file: $image_file"
if [ "$image_file" != "" ]; then
image_ext="$(sed -n 's/.*\(\..\{3\}\).*/\1/p' <<< $image_file)"
image_out="$image_name$image_ext"
image_download_url="$apod_url$image_file"
echo "APOD image URL: $image_download_url"
echo -n "Downloading to $image_out... "
curl -s -o "$image_out" "$image_download_url"
echo "Done."
else
echo "APOD image URL not found"
echo "Exiting."
fi
tjones fucked around with this message at 02:42 on Aug 25, 2021
|
#
¿
May 3, 2021 23:24
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 3, 2024 14:58
|
|