summaryrefslogtreecommitdiff
path: root/oedwordday.sh
blob: d54d40304072ef14b5689a4f1d13a69a29ee87a6 (plain)
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
#!/bin/bash

word=$( curl --silent https://www.lexico.com/ | hxnormalize -x | hxselect -i "a.linkword" | grep -o '>.*<' | sed 's/[><]//g')
appId=
key=
language=en-gb
OPTS='--silent -L -H "app_id: $appId" -H "app_key: $key"'

entriesUrl=https://od-api.oxforddictionaries.com/api/v2/entries/$language/$word

# get definition of headword
result=$(eval curl $OPTS $entriesUrl)
ret=$?
if [ "$ret" -ne 0 ]
then
  echo "cURL error $ret when fetching."
  exit
fi

# Get first definition from received json
definition=$(echo $result | jq '.results[].lexicalEntries[].entries[0].senses[0].definitions[]')

# Get lexical category for first definition
lexicalCategory=$(echo $result | jq '.results[].lexicalEntries[0].lexicalCategory.text')

# Remove surrounding quotes
definition=$(echo "${definition:1: -1}")
lexicalCategory=$(echo "${lexicalCategory:1: -1}")

# Return word, lexical category and first definition.
echo ${word^}" - "$lexicalCategory" - "$definition