From 47bfd95a0ab5c8876ea5d861747e95fae799a78a Mon Sep 17 00:00:00 2001 From: xatier Date: Tue, 18 Jun 2024 22:51:41 -0500 Subject: [PATCH] =?UTF-8?q?fix(moedict.sh):=20fix=20bug=20on=20=E7=A0=B4?= =?UTF-8?q?=E9=9F=B3=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/moedict.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/moedict.sh b/bin/moedict.sh index 47aaa62..81b627f 100755 --- a/bin/moedict.sh +++ b/bin/moedict.sh @@ -13,7 +13,7 @@ urlencode() { lookup="$(echo -n "$1" | urlencode)" api="$(curl -Ss "https://www.moedict.tw/a/${lookup}.json")" -if [[ "$api" == *"404"* ]]; then +if [[ "$api" == *"404 Not Found"* ]]; then # single character not found if [[ ${#1} -eq 1 ]]; then (echo >&2 "$1 not found in moedict") @@ -39,4 +39,12 @@ else # some character has "(`讀音~)" prefix, e.g., https://www.moedict.tw/a/%E5%98%9B.json bopomofo="$(echo "$api" | jq -r '.h[0].b' | awk '{gsub(" ", "-");print}')" echo "$1 $bopomofo" + bopomofo="$(echo "$api" | jq -r '.h[1].b' | awk '{gsub(" ", "-");print}')" + if [[ "$bopomofo" != 'null' ]]; then + echo "$1 ($bopomofo)" + fi + bopomofo="$(echo "$api" | jq -r '.h[2].b' | awk '{gsub(" ", "-");print}')" + if [[ "$bopomofo" != 'null' ]]; then + echo "$1 ($bopomofo)" + fi fi