scripts

random scripts
git clone https://git.parazyd.org/scripts
Log | Files | Refs

urban (982B)


      1 #!/bin/sh
      2 #
      3 # Copy me if you can.
      4 # By parazyd
      5 #
      6 # Grab urbandictionary definitions
      7 
      8 api="https://api.urbandictionary.com/v0/define?term="
      9 
     10 term="$*"
     11 printf "Getting definition for \"%s\"...\n" "$term"
     12 term="$(echo $term | sed 's/ /%20/g')"
     13 
     14 data="$(curl -s "${api}${term}" | jq '.list')"
     15 
     16 echo "$data" | jq '.[0]'
     17 exit 0
     18 
     19 for i in $(seq 1 3); do
     20 	def="$(echo "$data" | jq '.['$i'].definition')"
     21 	[ "$def" = null ] && break
     22 	def="$(tput bold)$(tput setaf 4)Definition:$(tput sgr0) $def"
     23 
     24 	exa="$(echo "$data" | jq '.['$i'].example')"
     25 	exa="$(tput bold)$(tput setaf 4)Example:$(tput sgr0) $exa"
     26 
     27 	plu="$(echo "$data" | jq '.['$i'].thumbs_up')"
     28 	plu="$(tput bold)$(tput setaf 2)$plu+$(tput sgr0)"
     29 
     30 	min="$(echo "$data" | jq '.['$i'].thumbs_down')"
     31 	min="$(tput bold)$(tput setaf 1)$min-$(tput sgr0)"
     32 
     33 	printf "\n---------------------------------------\n\n"
     34 	printf "%s\n%s\n%s | %s\n" "$def" "$exa" "$plu" "$min" | \
     35 			sed -e 's/\\r\\n/\n/g' -e 's/\\"/"/g' | \
     36 			fmt -w 72 -t
     37 
     38 done