evilone89

Urbam Dictionizer

Aug 4th, 2025
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.81 KB | None | 0 0
  1. ud_perfectish ()
  2. {
  3.     term="$@";
  4.     sterm=$(echo $term | sed -e 's/ /%20/g');
  5.     jq_icase_filter=$(generate_permutations "${sterm}" | tr '{}' '[]' | tr -d ',');
  6.     function get_count ()
  7.     {
  8.         export num=0 check="init";
  9.         until [[ -z "${check}" ]]; do
  10.             let num++;
  11.             export cpage="&page=${num}";
  12.             export check="$(curl -skL "https://api.urbandictionary.com/v0/define?term=${sterm}${cpage}" | jq -M -r '.list[]')";
  13.         done && export num=$((${num}-1))
  14.     };
  15.     get_count;
  16.     ( p=0;
  17.     l=-1;
  18.     declare -a ud_list;
  19.     for i in $(seq 1 1 ${num});
  20.     do
  21.         let p++;
  22.         if [[ $p -gt 1 ]]; then
  23.             export pg="&page=${i}";
  24.         fi;
  25.         curl "https://api.urbandictionary.com/v0/define?term=${sterm}${pg}" -s | jq -M -r '.list[] |select(.word|match("^'${jq_icase_filter}'$")) | (.defid|tostring) + " " + (.thumbs_up|tostring) + " " + (.thumbs_down|tostring) + " " + .word';
  26.     done ) | cat -n | sort -nk 3 | egrep -i "\b${term}\b$" | tail -1 | while read pnum defid tup tdwn rterm; do
  27.         let l++;
  28.         ud_list[${l}]=$(declare -p pnum defid tup tdwn rterm);
  29.         declare -p ud_list;
  30.         if [[ $tup -gt $tdwn ]] && [[ -n $(echo "${term}" | grep -i "${rterm}") ]]; then
  31.             curl -skL "https://api.urbandictionary.com/v0/define?defid=$defid" | jq -r -M '.list[].definition';
  32.             declare -p pnum defid tup tdwn rterm;
  33.         else
  34.             if [[ ${tup} -gt ${tdwn} ]]; then
  35.                 echo "${Yellow}Warning:${White} logic caused definition selected based on number of thumbs ups not to be a perfect match.  Definition for ${Cyan}${rterm}:${White}";
  36.                 curl -skL "https://api.urbandictionary.com/v0/define?defid=$defid" | jq -r -M '.list[].definition';
  37.             else
  38.                 echo "Thumbsdown outweigh thumbs up or rterm doesnt match term, please verify manually.";
  39.                 echo -e "${pnum} ${defid} ${tup} ${tdwn} ${rterm}";
  40.                 echo -e "term is $(printf "%s\n" "${term}")\nrterm is $(printf "%s\n" "${rterm}")";
  41.                 echo -e "Here is the list of definitions you must sort through.";
  42.                 set +x;
  43.                 p=0;
  44.                 for fail in $(seq 1 1 ${num});
  45.                 do
  46.                     let p++;
  47.                     if [[ $p -gt 1 ]]; then
  48.                         export pg="&page=${fail}";
  49.                     fi;
  50.                     curl "https://api.urbandictionary.com/v0/define?term=${sterm}${pg}" -s | jq -M -r '.list[] |select(.word|match("^'${jq_icase_filter}'$")) | "https://api.urbandictionary.com/v0/define?defid=" + (.defid|tostring) + " " + (.thumbs_up|tostring) + " " + (.thumbs_down|tostring) + " " + .word';
  51.                 done;
  52.                 set +x;
  53.             fi;
  54.         fi;
  55.     done;
  56.     set +x
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment