This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcafe
executable file
·68 lines (54 loc) · 1.66 KB
/
gcafe
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
# Set appropriate month and date
if [ "$(date +%A)" = "Monday" ]; then
month="$(date +%B)"
day=$(date +%-d)
elif [ $(date +%u) -gt 5 ]; then
month="$(date -d-monday +%B)"
day=$(date -d-monday +%-d)
else
month="$(date -dlast-monday +%B)"
day=$(date -dlast-monday +%-d)
fi
menu_pdf="tmp/menu-${month}-${day}.pdf"
function get_menu {
# GCafe menu url template
url="https://flikcafes.compass-usa.com/cafeG/DiningMenus/Menu%20{month}%20{day}.pdf"
menu=$(echo "$url" | sed -E -e "s/\{month\}/${month}/g" -e "s/\{day\}/${day}/g")
curl -sf "$menu" -o "$menu_pdf" || exit 1
}
function get_days {
offset_x=220
width=400
height=130
monday_y=100
tuesday_y=230
wednesday_y=370
thursday_y=500
friday_y=630
declare -a days=( "monday" "tuesday" "wednesday" "thursday" "friday" )
declare -a day_offsets=( ${monday_y} ${tuesday_y} ${wednesday_y} ${thursday_y} ${friday_y} )
for i in "${!day_offsets[@]}"; do
output="tmp/${days[$i]}.txt"
pdftotext -x ${offset_x} -y ${day_offsets[$i]} -W ${width} -H ${height} -layout ${menu_pdf} ${output}
done
}
# get newest menu if not cached
if [ ! -f $menu_pdf ]; then
if [ -f tmp/menu-* ]; then
rm ./tmp/menu-*
fi
get_menu && get_days
fi
day=$(date +%A)
day_menu="tmp/${day,,}.txt"
if [ -f $day_menu ]; then
menu=$(sed 's/\o14//g' $day_menu)
printf "${day^} Menu\n"
printf '```\n'
printf "${menu}\n"
printf '```\n'
else
printf '${day^} menu is not available yet! Please check back in a little while.\n'
fi
printf 'For full menu, visit https://flikcafes.compass-usa.com/cafeG/Pages/Menu.aspx?lid=bnb'