summaryrefslogtreecommitdiff
path: root/oeddefine.sh
diff options
context:
space:
mode:
authorAsa Venton <asav1410@gmail.com>2020-10-19 13:06:27 +0100
committerAsa Venton <asav1410@gmail.com>2020-10-19 13:06:27 +0100
commitcc9d7c85b8ea083853ce91e2cbc3f594053b1de3 (patch)
treec06153bf5a024d5e5346cb5ee233579947808197 /oeddefine.sh
parent9bace3d0ca99eb71160b20e88a5f4eaf458e6394 (diff)
Rename file as define is no longer entirely representative of its function and intended goal
Diffstat (limited to 'oeddefine.sh')
-rwxr-xr-xoeddefine.sh148
1 files changed, 0 insertions, 148 deletions
diff --git a/oeddefine.sh b/oeddefine.sh
deleted file mode 100755
index 6bdad65..0000000
--- a/oeddefine.sh
+++ /dev/null
@@ -1,148 +0,0 @@
-#!/bin/bash
-
-read word
-word=$(echo $word | tr '[:upper:]' '[:lower:]')
-appId=
-appKey=
-language=en-gb
-OPTS='--silent -L -H "app_id: $appId" -H "app_key: $appKey"'
-maxSynonyms=10
-
-# function to provide data to a for loop
-_jq() {
- echo ${json} | base64 --decode | jq -r ${1}
-}
-
-_getdata() {
- # Take everything after final space as the requested word (assuming everything before the last space is a flag)
- word=$(echo $word | sed 's/.* //')
- lemmasUrl=https://od-api.oxforddictionaries.com/api/v2/lemmas/$language/$word
- # get lemmas to link an inflected form back to its headword (required to get definition)
- result=$(eval curl $OPTS $lemmasUrl)
- ret=$?
- if [ "$ret" -ne 0 ]
- then
- echo "cURL error $ret when fetching."
- exit
- fi
-
- # get definition of headword if it exists
- headWord=$(echo $result | jq '.results[0].lexicalEntries[0].inflectionOf[0].id')
- if [ "$headWord" == "null" ]
- then
- echo "Word not found. Use -h for help."
- exit
- fi
- entriesUrl=https://od-api.oxforddictionaries.com/api/v2/entries/$language/$headWord
- result=$(eval curl $OPTS $entriesUrl)
- ret=$?
- if [ "$ret" -ne 0 ]
- then
- echo "cURL error $ret when fetching."
- exit
- fi
-}
-
-# Return definition for the first sense of each lexical entry and create output string
-_define() {
- _getdata
- 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]') "
- examplePhrase=$(_jq '.entries[0].senses[0].examples[0].text')
- if [[ "$examplePhrase" != "null" ]]
- then
- output=$output" "$examplePhrase
- fi
- done
- echo $output
- exit 0
-}
-
-# Return etymology if available
-_etym() {
- _getdata
- output=$(echo "${result}" | jq '.results[].lexicalEntries[0].entries[0].etymologies[0]' | tr -d \")
- if [ -z "$output" ]
- then
- echo "No etymology found."
- else
- echo $output
- fi
- exit 0
-}
-
-# Return synonyms of first sense of first lexical entry
-_thes() {
- _getdata
- count=0
- 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
- if [[ $count -ge $maxSynonyms ]]
- then
- break
- fi
- done
- echo $output
- exit 0
-}
-
-# Get URL for first audio file in returned data
-_audio() {
- _getdata
- output=$(echo "${result}" | jq '.results[0].lexicalEntries[0].entries[0].pronunciations[0].audioFile' | tr -d \")
- echo $output
- exit 0
-}
-
-# Return first defintion with lexical category for Lexico's word of the day.
-_wod() {
- # Get word from lexico
- word=$( curl --silent https://www.lexico.com/ | hxnormalize -x | hxselect -i "a.linkword" | grep -o '>.*<' | sed 's/[><]//g')
- _getdata
- definition=$(echo $result | jq '.results[].lexicalEntries[].entries[0].senses[0].definitions[]')
- lexicalCategory=$(echo $result | jq '.results[].lexicalEntries[0].lexicalCategory.text')
- examplePhrase=$(echo $result | jq '.results[].lexicalEntries[0].entries[0].senses[0].examples[0].text')
- # Remove surrounding quotes
- definition=$(echo "${definition:1: -1}")
- lexicalCategory=$(echo "${lexicalCategory:1: -1}")
- if [[ "$examplePhrase" != "null" ]]
- then
- output=$word" - "$lexicalCategory" - "$definition" - "$examplePhrase
- else
- output=$word" - "$lexicalCategory" - "$definition
- fi
- echo $output
- exit 0
-}
-
-_help() {
- echo "Usage: !oeddefine [option] [word]. Options: -h help -t thesaurus -e etymology -d define -a audio -s source"
- exit 0
-}
-
-if [[ ${word} == "-h" ]] || [[ ${word} == "--help" ]] || [[ -z $word ]]
-then
- _help
-elif [[ ${word} == "--source" ]] || [[ ${word} == "-s" ]]
-then
- echo "https://www.blatech.co.uk/ars/oeddefine"
- exit 0
-elif [[ ${word} =~ "-t" ]]
-then
- _thes
-elif [[ ${word} =~ "-et" ]]
-then
- _etym
-elif [[ ${word} =~ "-a" ]]
-then
- _audio
-elif [[ ${word} =~ "-d" ]]
-then
- _wod
-else
- _define
-fi