#/usr/lib/perl 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"; sub info{ my $fai = shift @_; my $json; { local $/; #Enable 'slurp' mode open my $fh, "<", "/home/canouan/bot-irc/". $dump_dir."/". $fai; $json = <$fh>; close $fh; } my $data = decode_json($json); 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/canouan/bot-irc/wrk-dir/". $fai.".info"; my $fh2; open ($fh2, '>', $filename) or die "Impossible d'ouvrir le fichier $filename en écriture"; # print $fh2 "Description : ". $description . " Le site est ". $site .". Le salon pour discuter est : ". $salon ." et le mail de contact est : ". $contact . ". Ce FAI a été crée le ". $date_crea ." et il a rejoint la fédé le ". $date_jffdn ."\n"; 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; } sub adh{ my $fai = shift @_; my $json; { local $/; #Enable 'slurp' mode open my $fh, "<", "/home/canouan/bot-irc/dump/". $fai; $json = <$fh>; close $fh; } my $data = decode_json($json); 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/canouan/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; } sub adh{ my $fai = shift @_; my $json; { local $/; #Enable 'slurp' mode open my $fh, "<", "/home/canouan/bot-irc/dump/". $fai; $json = <$fh>; close $fh; } my $data = decode_json($json); unless (!length $data->{"ispformat"}->{"memberCount"}) { $nb_adh = $data->{"ispformat"}->{"memberCount"}; } unless (!length $data->{"ispformat"}->{"subscriberCount"}) { $nb_abo = $data->{"ispformat"}->{"subscriberCount"}; } my $filenameadh = "/home/canouan/bot-irc/wrk-dir/ffdn.adh"; my $filenameabo = "/home/canouan/bot-irc/wrk-dir/ffdn.abo"; 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; } # sub readlol { # my $fai = shift @_; # my $filename = "/home/canouan/bot-irc/". $wrk_dir."/". $fai; # my $fh; # open ($fh, '<', $filename) or die "Impossible d'ouvrir le fichier $filename en lecture"; # while (my $line = <$fh>) # { # print $line; # } # close $fh; # } my @filesdump = ; my $filedump; foreach $filedump (@filesdump) { $filedump =~ s{/home/canouan/bot-irc/dump/}{}; info ("$filedump"); } foreach $filedump (@filesdump) { $filedump =~ s{/home/canouan/bot-irc/dump/}{}; adh ("$filedump"); } my $adh_ffdn; foreach $filedump (@filesdump) { $filedum^=~ s{/home/canouan/bot-irc/dump/}{}; adh_ffdn ("filedump"); }