From 6a08b19d100b5cb7963fdde6c8c7c44d6b85f7e6 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 28 Sep 2023 13:10:57 +0300 Subject: [PATCH] feat: outlinestats.elv --- outlinestats.elv | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 outlinestats.elv diff --git a/outlinestats.elv b/outlinestats.elv new file mode 100755 index 0000000..2ffc67e --- /dev/null +++ b/outlinestats.elv @@ -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 + -- 2.44.1