123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #/usr/lib/perl
- # Copyright (c) 2014 Daniel Jakots <vigdis@chown.me>
- # Permission to use, copy, modify, and distribute this software for any
- # purpose with or without fee is hereby granted, provided that the above
- # copyright notice and this permission notice appear in all copies.
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- use strict;
- use warnings;
- binmode STDOUT, ":utf8";
- use utf8;
- use JSON;
- # FAI variables
- my $nb_adh = 0; # nombre d'adhérents
- my $nb_abo = 0; # nombre d'abonnés
- my $site = ""; # site web
- my $salon = ""; # salon irc/xmpp
- my $statut = 0; # étape de 1 à 8 du FAI
- my $date_crea = ""; # date de la création de l'asso
- my $date_jffdn = ""; # date de la rentrée dans la fédé
- my $contact = ""; # email de contact
- my $description = ""; # description de l'asso
- # variables des dossiers
- my $dump_dir = "dump";
- my $wrk_dir = "wrk-dir";
- # récupère les infos du json et les mets dans le ficher au nom du FAI
- sub info{
- my $fai = shift @_;
- my $json;
- {
- local $/; #Enable 'slurp' mode
- open my $fh, "<", "/home/daga/bot-irc/". $dump_dir."/". $fai;
- $json = <$fh>;
- close $fh;
- }
-
- my $data = decode_json($json);
- # pour chaque valeur on vérifie que ce n'est pas nul, si c'est le cas on
- # indique N/A (not available)
- if (!length $data->{"ispformat"}->{"memberCount"}) {
- $nb_adh = "N/A";
- }
- else {
- $nb_adh = $data->{"ispformat"}->{"memberCount"};
- }
- if (!length $data->{"ispformat"}->{"subscriberCount"}) {
- $nb_abo = "N/A";
- }
- else {
- $nb_abo = $data->{"ispformat"}->{"subscriberCount"};
- }
-
- if (!length $data->{"ispformat"}->{"website"}) {
- $site = "N/A";
- }
- else {
- $site = $data->{"ispformat"}->{"website"};
- }
- if (!length $data->{"ispformat"}->{"chatrooms"}) {
- $salon = "N/A";
- }
- else {
- $salon = $data->{"ispformat"}->{"chatrooms"}->[0];
- }
-
- if (!length $data->{"ispformat"}->{"progressStatus"}) {
- $statut = "N/A";
- }
- else {
- $statut = $data->{"ispformat"}->{"progressStatus"};
- }
-
- if (!length $data->{"ispformat"}->{"creationDate"}) {
- $date_crea = "N/A";
- }
- else{
- $date_crea = $data->{"ispformat"}->{"creationDate"};
- }
- if (!length $data->{"ispformat"}->{"ffdnMemberSince"}) {
- $date_jffdn = "N/A";
- }
- else {
- $date_jffdn = $data->{"ispformat"}->{"ffdnMemberSince"};
- }
- if (!length $data->{"ispformat"}->{"email"}) {
- $contact = "N/A";
- }
- else {
- $contact = $data->{"ispformat"}->{"email"};
- }
- if (!length $data->{"ispformat"}->{"description"}) {
- $description = "N/A";
- }
- else {
- $description = $data->{"ispformat"}->{"description"};
- }
- my $filename = "/home/daga/bot-irc/wrk-dir/". $fai.".info";
- # On indique dans le fichier la phrase que le bot va répondre
- my $fh2;
- open ($fh2, '>', $filename) or die "Impossible d'ouvrir le fichier $filename en écriture";
- print $fh2 $description . ". Site : ". $site ." - Salon de discussion : ". $salon ." - Adresse de contact : ". $contact . " - Crée le ". $date_crea .", il a rejoint la fédé le ". $date_jffdn ."\n";
- close $fh2;
- }
- # récupère les infos du json et les mets dans le ficher au nom du FAI.adh
- sub adh{
- my $fai = shift @_;
- my $json;
- {
- local $/; #Enable 'slurp' mode
- open my $fh, "<", "/home/daga/bot-irc/dump/". $fai;
- $json = <$fh>;
- close $fh;
- }
-
- my $data = decode_json($json);
- # pour chaque valeur on vérifie que ce n'est pas nul, si c'est le cas on
- # indique N/A (not available)
- if (!length $data->{"ispformat"}->{"memberCount"}) {
- $nb_adh = "N/A";
- }
- else {
- $nb_adh = $data->{"ispformat"}->{"memberCount"};
- }
-
- if (!length $data->{"ispformat"}->{"subscriberCount"}) {
- $nb_abo = "N/A";
- }
- else {
- $nb_abo = $data->{"ispformat"}->{"subscriberCount"};
- }
- my $filename = "/home/daga/bot-irc/wrk-dir/". $fai.".adh";
- my $fh2;
- open ($fh2, '>', $filename) or die "Impossible d'ouvrir le fichier $filename en écriture";
- print $fh2 $nb_adh ." adhérent·e·s (et ".$nb_abo." abonné·e·s).\n";
- close $fh2;
- }
- # indique le nombre d'adh et d'abo dans l'ensemble des FAI ; fichier : ffdn.adh
- sub adh_abo_ffdn {
-
- my @filesdump = </home/daga/bot-irc/dump/*>;
- my $filedump;
- my $adh_ffdn = 0;
- my $abo_ffdn = 0;
- foreach $filedump (@filesdump) {
- $filedump =~ s{/home/daga/bot-irc/dump/}{};
- my $json;
- {
- local $/; #Enable 'slurp' mode
- open my $fh, "<", "/home/daga/bot-irc/dump/". $filedump;
- $json = <$fh>;
- close $fh;
- }
-
- my $data = decode_json($json);
- # si pas d'info, tant pis
- unless (!length $data->{"ispformat"}->{"memberCount"}) {
- $nb_adh = $data->{"ispformat"}->{"memberCount"};
- }
-
- unless (!length $data->{"ispformat"}->{"subscriberCount"}) {
- $nb_abo = $data->{"ispformat"}->{"subscriberCount"};
- }
- my $fh2;
- open ($fh2, '>', $filedump) or die "Impossible d'ouvrir le fichier $filedump en écriture";
- # on incrémente pour chaque FAI
- $adh_ffdn += $nb_adh;
- $abo_ffdn += $nb_abo;
- close $fh2;
- }
-
- my $filenameadh = "/home/daga/bot-irc/wrk-dir/ffdn.adh";
- my $fh3;
- # on met l'info dans le fichier
- open ($fh3, '>', $filenameadh) or die "Impossible d'ouvrir le fichier $filenameadh en écriture";
- print $fh3 "La fédé compte ".$adh_ffdn ." adhérent·e·s et ". $abo_ffdn ." abonné·e·s";
- close $fh3;
-
- }
- # pour chaque FAI on génère l'info
- my @filesdump = </home/daga/bot-irc/dump/*>;
- my $filedump;
- foreach $filedump (@filesdump) {
- $filedump =~ s{/home/daga/bot-irc/dump/}{};
- info ("$filedump");
- }
- # pour chaque FAI on génère l'info du nombre d'adhérents
- foreach $filedump (@filesdump) {
- $filedump =~ s{/home/daga/bot-irc/dump/}{};
- adh ("$filedump");
- }
- # on génère l'info du nombre d'adhérents de la fédé
- adh_abo_ffdn();
|