summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorars <asav1410@gmail.com>2020-10-20 19:48:55 +0100
committerars <asav1410@gmail.com>2020-10-20 19:48:55 +0100
commitc2e739c7f2337ce37b84de4e0c5921702347009f (patch)
tree12f3de9b4c9db6b017a1047dc979bbf62a607771
parent013b44bf90243a0fdc4233ed8730815338886bd6 (diff)
Re add full stop and quotes to _define output that were lost in earlier commit. Add error handling in _thes when no synonyms are returned.
-rwxr-xr-xoedquery.sh21
1 files changed, 14 insertions, 7 deletions
diff --git a/oedquery.sh b/oedquery.sh
index 12811c8..b99cf0a 100755
--- a/oedquery.sh
+++ b/oedquery.sh
@@ -67,11 +67,11 @@ _define() {
for json in $(echo "${result}" | jq -r '.results[].lexicalEntries[] | @base64')
do
output="$output $(_jq '.lexicalCategory.text'): "
- output="$output $(_jq '.entries[0].senses[0].definitions[0]') "
+ output="$output $(_jq '.entries[0].senses[0].definitions[0]'). "
examplePhrase=$(_jq '.entries[0].senses[0].examples[0].text')
if [[ "$examplePhrase" != "null" ]]
then
- output=$output" "$examplePhrase
+ output=$output" \"$examplePhrase\""
fi
done
echo $output
@@ -95,7 +95,7 @@ _etym() {
_thes() {
_getdata
count=0
- for json in $(echo "${result}" | jq -r '.results[].lexicalEntries[0].entries[0].senses[0].synonyms[] | @base64'); do
+ for json in $(echo "${result}" | jq -r '.results[].lexicalEntries[0].entries[0].senses[0].synonyms[]? | @base64'); do
output="$output $(_jq '.text'), "
((count=count+1))
# Limit output to a resonable number of synonyms
@@ -104,10 +104,17 @@ _thes() {
break
fi
done
- # remove trailing comma and space
- output=$(echo $output | sed '$s/,$//')
- echo $output
- exit 0
+
+ if [[ -z $output ]]
+ then
+ echo "No synonyms found."
+ exit 0
+ else
+ # remove trailing comma
+ output=$(echo $output | sed '$s/,$//')
+ echo $output
+ exit 0
+ fi
}
# Get URL for first audio file in returned data