-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather-yr-pdf
executable file
·41 lines (38 loc) · 1.51 KB
/
weather-yr-pdf
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
#!/bin/env bash
shopt -s nullglob
WEATHERPATH="/tmp/weather"
OTHER_WEATHER_PATH="/tmp/weather/other"
DATE="$(date +%Y-%m-%d)"
LOCATION_LIST="$HOME/Documents/WeatherPlaces"
weatherNow () {
[[ ! -d "$WEATHERPATH" ]] && ( mkdir -p "$WEATHERPATH" )
find $WEATHERPATH -maxdepth 1 -mmin +59 -type f -name "*.pdf" -delete # Delete every pdf file older than a hour
MAIN_WEATHER_LOCATION_URL=$(printf '%s\n' "${places[0]}" | awk '{print $2}')
if [[ ! -f "$WEATHERPATH/$DATE-forecast.pdf" ]]; then
cd $WEATHERPATH
wget -O "$DATE-forecast.pdf" "$MAIN_WEATHER_LOCATION_URL"
fi
devour zathura "$WEATHERPATH/$DATE-forecast.pdf"
}
viewOtherPlaces () {
LOCATION=$(printf '%s\n' "${places[@]}" | dmenu -i -c -l 20 -p "Places: ")
[[ ! "$LOCATION" ]] && exit 1
[[ ! -d "$OTHER_WEATHER_PATH" ]] && ( mkdir -p "$OTHER_WEATHER_PATH" )
find $OTHER_WEATHER_PATH -maxdepth 1 -mmin +59 -type f -name "*.pdf" -delete
LOCATION_NAME=$(echo $LOCATION | awk '{print $1}')
LOCATION_URL=$(echo $LOCATION | awk '{print $2}')
if [[ ! -f "$OTHER_WEATHER_PATH/$DATE-$LOCATION_NAME.pdf" ]]; then
cd $OTHER_WEATHER_PATH
wget -O "$DATE-$LOCATION_NAME.pdf" "$LOCATION_URL"
fi
devour zathura "$OTHER_WEATHER_PATH/$DATE-$LOCATION_NAME.pdf"
}
mapfile -t places < "$LOCATION_LIST"
while getopts "nd" opt
do
case ${opt} in
n ) weatherNow;; # n for now
d ) viewOtherPlaces;; # d for different places
/? ) echo "Invalid Option: "; exit 1;;
esac
done