-
Notifications
You must be signed in to change notification settings - Fork 11
/
freshen_local_nasr_old.sh
54 lines (43 loc) · 1.58 KB
/
freshen_local_nasr_old.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -eu # Always put this in Bourne shell scripts
IFS=$(printf '\n\t') # Always put this in Bourne shell scripts
# Download latest documents from from FAA
# The script begins here
# Set some basic variables
declare -r PROGNAME=$(basename "$0")
declare -r PROGDIR=$(readlink -m "$(dirname "$0")")
# Get the number of remaining command line arguments
NUMARGS=$#
# Validate number of command line parameters
if [ "$NUMARGS" -ne 1 ] ; then
echo "Usage: $PROGNAME <DOWNLOAD_ROOT_DIR>" >&2
exit 1
fi
# Get command line parameter
DOWNLOAD_ROOT_DIR=$(readlink -f "$1")
# Name of file used as last refresh marker
REFRESH_MARKER="${PROGDIR}/last_nasr_refresh"
if [ ! -d "$DOWNLOAD_ROOT_DIR" ]; then
echo "$DOWNLOAD_ROOT_DIR doesn't exist" >&2
exit 1
fi
# Exit if we ran this command within the last 24 hours (adjust as you see fit)
if [ -e "${REFRESH_MARKER}" ] && [ "$(date +%s -r "${REFRESH_MARKER}")" -gt "$(date +%s --date="24 hours ago")" ]; then
echo "Documents updated within last 24 hours, exiting"
exit 0
fi
# Update the time of this file so we can check when we ran this last
touch "${REFRESH_MARKER}"
# Update local cache of 28 and 56 day files
set +e
wget \
--directory-prefix="$DOWNLOAD_ROOT_DIR" \
--recursive \
-l2 \
--span-hosts \
--domains=faa.gov \
--timestamping \
--ignore-case \
--accept-regex '.*NASR_Subscription.*|.*28DaySubscription.*.zip' \
https://www.faa.gov/air_traffic/flight_info/aeronav/aero_data/NASR_Subscription/
set -e