-
Notifications
You must be signed in to change notification settings - Fork 1
/
sushiro
executable file
·148 lines (139 loc) · 4.14 KB
/
sushiro
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
#
# sushiro 0.0.7
# (C) 2018 redpeacock78
# GPLv3 is applied to this script
######################################
#Randomly display the menu of Sushiro.
#Grobals:
# CACHE
#Arguments:
# -h
# -l
# -p
# -k
# -a
# -f
#Returns:
# None
######################################
###USAGE###
[[ "${1}" = "-h" ]] && \
printf "sushiro version 0.0.7\n\nUSAGE: sushiro [OPTIONS] [ANYTHING]\nOptions:\n -l [NUMBER]\n Randomly display the number of specified menus\n (By default it display one item)\n -p [MENU_NAME]\n Display price of menu corresponding to name\n (If not specified,all menus and prices will be displayed)\n -k [MENU_NAME]\n Display the calorie of the name corresponding menu\n (If not specified,all menus and calories are displayed)\n -a\n Display names of all menus(158 species in total)\n -f\n Fetch menus from www.akindo-sushiro.co.jp\n (The menu will be saved in /usr/local/share/sushiro_cache)\n *In case of linuxbrew it is 'directory where linuxbrew is installed/share/sushiro_cache'.*\n" && \
exit 0
###DEFAULT_PARAMETER###
#LINES=1
###FETCH###
#CACHE="/usr/local/share/sushiro_cache"
CACHE=$(echo "$(dirname "${0}")" | sed 's#bin#share/sushiro_cache#')
#[[ "${1}" = "-f" ]] && \
# curl -s 'https://www.akindo-sushiro.co.jp/menu/' -o "$CACHE" &&\
#exit 0
[[ ! -f "${CACHE}" ]] && \
curl -s 'https://www.akindo-sushiro.co.jp/menu/' -o "${CACHE}"
###TEXT###
while [[ "${#}" -gt 0 ]]; do
##RONDOM_MENUS##
if [[ "${1}" = "-l" ]]; then
shift && \
LINES="${1:-1}"
cat "${CACHE}" \
| tr -d '\r' \
| grep -e '="ttl"' -e price \
| sed 's/<[^>]*>//g;s/ + /+/g;s/場合 /場合/g;/^$/d' \
| tr '\n' ' ' \
| sed 's/税 /税 /g;s/ /,/g' \
| awk '{gsub(/kcal,/,"kcal\n");print}' \
| sort \
| uniq \
| sed '//d' \
| awk -F ',' '{print $1}' \
| sort -R \
| grep "\S" \
| shuf -n "${LINES}" && \
exit 0
##MENUS_PRICES##
elif [[ "${1}" = "-p" ]]; then
shift && \
PRICES="${1}"
shift
cat "${CACHE}" \
| tr -d '\r' \
| grep -e '="ttl"' -e price \
| sed 's/<[^>]*>//g;s/ + /+/g;s/場合 /場合/g;/^$/d' \
| tr '\n' ' ' \
| sed 's/税 /税 /g;s/ /,/g' \
| awk '{gsub(/kcal,/,"kcal\n");print}' \
| sort \
| uniq \
| sed '//d' \
| grep "${PRICES}" \
| awk -F ',' '{print $1,$2}' \
| sed 's/倍とろ$//' \
| grep "\S" && \
exit 0
##MENUS_CALORIES##
elif [[ "${1}" = "-k" ]]; then
shift && \
CALORIES="${1}"
shift
cat "${CACHE}" \
| tr -d '\r' \
| grep -e '="ttl"' -e price \
| sed 's/<[^>]*>//g;s/ + /+/g;s/場合 /場合/g;/^$/d' \
| tr '\n' ' ' \
| sed 's/税 /税 /g;s/ /,/g' \
| awk '{gsub(/kcal,/,"kcal\n");print}' \
| sort \
| uniq \
| sed '//d' \
| grep "${CALORIES}" \
| awk -F ',' '{print $1,$3}' \
| sed 's/ 100円+税//' \
| grep "\S" && \
exit 0
##SHOW_ALL_MENUS##
elif [[ "${1}" = "-a" ]]; then
cat "${CACHE}" \
| tr -d '\r' \
| grep -e '="ttl"' -e price \
| sed 's/<[^>]*>//g;s/ + /+/g;s/場合 /場合/g;/^$/d' \
| tr '\n' ' ' \
| sed 's/税 /税 /g;s/ /,/g' \
| awk '{gsub(/kcal,/,"kcal\n");print}' \
| sort \
| uniq \
| sed '//d' \
| awk -F, 'NR>1{print $1}' \
| grep "\S" && \
exit 0
##FETCH##
elif [[ "${1}" = "-f" ]]; then
if [[ -e "${CACHE}" ]]; then
read -p "Are you sure you want to overwrite the menu? [Y/n] " ANSWER
case "${ANSWER}" in
"" | "Y" | "y" | "yes" | "Yes" | "YES" )
curl -s 'https://www.akindo-sushiro.co.jp/menu/' -o "${CACHE}" && \
printf "DONE!!\n" && \
exit 0;;
* )
printf "The cache was not overwritten.\n" && \
exit 2;;
esac
else
curl -s 'https://www.akindo-sushiro.co.jp/menu/' -o "${CACHE}" && \
printf "SUCCESS!!\n" && \
exit 0
fi
else
printf "sushiro: missing operand\nTry 'sushiro -h' for more information.\n" && \
exit 2
fi
done
[[ -z "${1}" ]] && \
printf "sushiro: missing operand\nTry 'sushiro -h' for more information.\n" && \
exit 2