From 4ea16c163a0f1533863236f89dd848638ded7180 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 17:42:02 +0100 Subject: [PATCH] curl and show stats from GraphQL api --- rapport_activite/rapport_activite.sh | 39 ++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 1f3395b..5558244 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -30,6 +30,17 @@ source "/etc/mobilizon.chapril.org/mobilizonchaprilorg.conf" IPV4_PATTERN="[0-9]{1,3}(\.[0-9]{1,3}){3}" IPV6_PATTERN="[0-9a-f]{0,4}(:[0-9a-f]{0,4}){2,7}" + +# TODO métriques à récupérer +# https://docs.joinmobilizon.org/contribute/graphql_api/ +API_URL="https://mobilizon.chapril.org/api/" + +# get statistics from the graphQL api of the website + json=$(curl -X POST \ + -H "Content-Type: application/json" \ + --data '{"query":"{\n statistics {\n numberOfUsers\n numberOfEvents\n numberOfLocalEvents\n numberOfComments\n numberOfLocalComments\n numberOfGroups\n numberOfLocalGroups\n numberOfInstanceFollowers\n numberOfInstanceFollowings\n }\n}\n"}' $API_URL) + +echo $json; # help() { @@ -73,9 +84,19 @@ generateHTTPReport() echo } +# display the value of a key in the json fetched with curl +function show +{ + # to navigate to sub keys like data.statistics.my_key , we must use multiple -e extract options + local value=$(echo "$json" | jshon -e "data" -e "statistics" -e $1 -u) + printf " $key=$value" +} + # generateSpecificReport() { + + local monthEnglish="$1" local year="$2" local yearMonth="$3" @@ -90,11 +111,19 @@ generateSpecificReport() echo "Nombre d'ipv6 utilisatrices du service = $ipv6UserCount" echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))" - # TODO métriques à récupérer - # https://docs.joinmobilizon.org/contribute/graphql_api/ - echo "Nombre de comptes utilisateurs" - echo "Nombre d'évènements passés" - echo "Nombre d'évènements à venir" + +# echo "Nombre de comptes utilisateurs = " + show "numberOfEvents" + show "numberOfLocalEvents" + show "numberOfGroups" + show "numberOfLocalGroups" + show "numberOfComments" + show "numberOfLocalComments" + show "numberOfInstanceFollowers" + show "numberOfInstanceFollowings" + show "numberOfUsers" +# echo "Nombre d'évènements passés" +# echo "Nombre d'évènements à venir" echo }