annna-meme-recommend - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- annna-meme-recommend (627B) --- 1 #!/bin/sh 2 3 if [ $# -lt 1 ]; 4 then 5 printf "usage: %s hashtag\n" "$(basename "$0")" >&2 6 exit 1 7 fi 8 9 export PATH="$HOME/bin:$PATH" 10 11 hashtagfile="$HOME/bin/modules/hashtags/hashtags.txt" 12 13 hashtag="$1" 14 15 # Scale allowed errors by input hashtag length. 16 hashtaglen=$(($(utf8expr length "$hashtag") - 1)) 17 case $hashtaglen in 18 0|1) 19 nerrors=1;; 20 2|3) 21 nerrors=2;; 22 4|5) 23 nerrors=3;; 24 6|7) 25 nerrors=4;; 26 8|9) 27 nerrors=5;; 28 10|11) 29 nerrors=6;; 30 12|13) 31 nerrors=7;; 32 *) 33 nerrors=8;; 34 esac 35 36 37 # n differences == -4; up to 8 38 agrep -i -$nerrors "^#${hashtag} " "${hashtagfile}" \ 39 | shuf 2>/dev/null \ 40 | head -n 5 \ 41 | cut -d' ' -f 1 \ 42 | tr "\n" " " 43