bird-name - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
bird-name (673B) | |
--- | |
1 #!/bin/sh | |
2 # | |
3 # Original code by josuah. Thanks! | |
4 # | |
5 | |
6 birdsrc="https://www.birds.cornell.edu/clementschecklist/wp-content/uplo… | |
7 | |
8 # Cache dir for bird name csv. | |
9 tmpdir="/home/annna/tmp" | |
10 | |
11 [ -f ${tmpdir}/bird.csv ] || curl "$birdsrc" \ | |
12 | awk -F "," ' | |
13 NR == 1 { for (f = 1; f <= NF && $f != "SCI_NAME"; f++); } | |
14 NR > 1 { gsub(/[[(].*[])]/, ""); sub(".* ", "", $f) } | |
15 length($f) > 3 && length($f) <= 6 && !F[$f]++ { print $f } | |
16 ' > ${tmpdir}/bird.csv | |
17 | |
18 # Get two names so it sounds more intellectual. | |
19 awk -v r=$RANDOM ' | |
20 BEGIN { srand(r) } { bird[NR] = $0 } | |
21 END { print bird[int(rand() * NR)] " " bird[int(rand() * NR)]; } | |
22 ' ${tmpdir}/bird.csv | |
23 |