DEVELOPMENT ENVIRONMENT

~liljamo/scripts

6a08b19d100b5cb7963fdde6c8c7c44d6b85f7e6 — Jonni Liljamo 1 year, 1 month ago afa4462 master
feat: outlinestats.elv
1 files changed, 25 insertions(+), 0 deletions(-)

A outlinestats.elv
A outlinestats.elv => outlinestats.elv +25 -0
@@ 0,0 1,25 @@
#!/usr/bin/env elvish
# usage:
# ./outlinestats.elv docs.example.com ol_api_xyz123

use str

var outlineInstance = $args[0]
var apiKey = $args[1]

var words = 0
var chars = 0

var documents = (curl -sL -X 'POST' -H 'authorization: Bearer '$apiKey ^
    -H 'content-type: application/json' -H 'accept: application/json' ^
    -d '{"offset": 0, "limit": 100}' 'https://'$outlineInstance'/api/documents.list')

var data = (echo $documents | from-json)[data]

each {|doc|
    set words = (+ $words (str:split ' ' $doc[text] | count))
    set chars = (+ $chars (str:split '' $doc[text] | count))
} $data

printf "words: %g\nchars: %g\n" $words $chars