Browse Source

bump le copyright et on arrete de s'amuser a parser deux fois les jsons ...

Daniel Jakots 10 years ago
parent
commit
1ef0d99e22
1 changed files with 6 additions and 35 deletions
  1. 6 35
      json-file.pl

+ 6 - 35
json-file.pl

@@ -1,6 +1,6 @@
 #!/bin/env perl
 #!/bin/env perl
 
 
-# Copyright (c) 2014 Daniel Jakots <vigdis@chown.me>
+# Copyright (c) 2014, 2015 Daniel Jakots <vigdis@chown.me>
 
 
 # Permission to use, copy, modify, and distribute this software for any
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
 # purpose with or without fee is hereby granted, provided that the above
@@ -25,6 +25,8 @@ use JSON;
 # FAI variables
 # FAI variables
 my $nb_adh = 0; # nombre d'adhérents
 my $nb_adh = 0; # nombre d'adhérents
 my $nb_abo = 0; # nombre d'abonnés
 my $nb_abo = 0; # nombre d'abonnés
+my $nb_adh_ffdn = 0; # nombre d'adhérents
+my $nb_abo_ffdn = 0; # nombre d'abonnés
 my $site = ""; # site web
 my $site = ""; # site web
 my $salon = ""; # salon irc/xmpp
 my $salon = ""; # salon irc/xmpp
 my $statut = 0; # étape de 1 à 8 du FAI
 my $statut = 0; # étape de 1 à 8 du FAI
@@ -140,6 +142,7 @@ sub adh{
     }
     }
     else {
     else {
 	$nb_adh = $data->{"ispformat"}->{"memberCount"};
 	$nb_adh = $data->{"ispformat"}->{"memberCount"};
+	$nb_adh_ffdn += $nb_adh;
     }
     }
 
 
     if (!length $data->{"ispformat"}->{"subscriberCount"}) {
     if (!length $data->{"ispformat"}->{"subscriberCount"}) {
@@ -147,6 +150,7 @@ sub adh{
     }
     }
     else {
     else {
 	$nb_abo = $data->{"ispformat"}->{"subscriberCount"};
 	$nb_abo = $data->{"ispformat"}->{"subscriberCount"};
+	$nb_abo_ffdn += $nb_abo;
     }
     }
 
 
     my $filename = "/home/daga/bot-irc/wrk-dir/". $fai.".adh";
     my $filename = "/home/daga/bot-irc/wrk-dir/". $fai.".adh";
@@ -158,45 +162,12 @@ sub adh{
 # indique le nombre d'adh et d'abo dans l'ensemble des FAI ; fichier : ffdn.adh
 # indique le nombre d'adh et d'abo dans l'ensemble des FAI ; fichier : ffdn.adh
 sub adh_abo_ffdn {
 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 $filenameadh = "/home/daga/bot-irc/wrk-dir/ffdn.adh";
 
 
     my $fh3;
     my $fh3;
 # on met l'info dans le fichier
 # on met l'info dans le fichier
     open ($fh3, '>', $filenameadh) or die "Impossible d'ouvrir le fichier $filenameadh en écriture";
     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";
+    print $fh3 "La fédé compte ".$nb_adh_ffdn ." adhérent·e·s et ". $nb_abo_ffdn ." abonné·e·s";
     close $fh3;
     close $fh3;
 
 
 }
 }