Hello
i think it could be useful for someone, maybe with some modification.
I did this little perl script to download the rates file on myvoiptraffic website and to generate the CSV file which can be imported in a2billing.
It generates a CSV file with these items :
PREFIX,DESTINATION,SELLRATE,BUYRATE,BUYINITBLOCK,BUYMINBLOCK,SELLINITBLOCK,SELLMINBLOCK
Firstly you need to install xls2csv tool, using this tutorial :
http://software.krimnet.com/xls2csv/gui ... ubuntu.htmand then copy this script in an executable file :
Code:
#!/usr/bin/perl -w
use warnings;
my $myVoipTrafficURL = "https://www.myvoiptraffic.com/public/download/ratelist_prem.xls";
my $marge=2; #What you want to apply to the buying rate
my $j=0;
my $fileRateMvtPre="";
my $fileRateA2B="ratelist_prem_a2b_";
my $cmd="";
my $SELLRATE;
my $BUYMINBLOCK1;
my $BUYMINBLOCK2;
my $SELLMINBLOCK1;
my $SELLMINBLOCK2;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $datestring = sprintf("%4d%02d%02d%02d%02d",($year + 1900),($mon+1),$mday,$hour,$min);
#Recuperation fichier xls
system("wget -t 3 ".$myVoipTrafficURL);
$fileRateMvtPre= "ratelist_prem_".$datestring;
$cmd = "mv ratelist_prem.xls ".$fileRateMvtPre.".xls";
system($cmd);
$cmd = "";
# conversion de la feuille Numberplan en csv
system("xls2csv -x ".$fileRateMvtPre.".xls -w Numberplan -c ".$fileRateMvtPre.".csv");
# ouverture du fichier définitif CSV
$fileRateA2B = $fileRateA2B.$datestring;
open FICHIER_CSV,"< ".$fileRateMvtPre.".csv"
or die "Le fichier n'existe pas CSV ! : $!\n";
open FICHIER_CSV_A2B,"> ".$fileRateA2B.".csv"
or die "Le fichier n'existe pas A2B ! : $!\n";
$ligne = <FICHIER_CSV>;
while($ligne = <FICHIER_CSV>)
{
#Récupération de la ligne CSV du fichier de MVT
chomp($ligne);
($DESTINATION[$j],$PREFIX[$j],$BUYRATE[$j],$HIGHER[$j]) = split /,/,$ligne;
#Calcul des sellrate et sellblocks
$SELLRATE = $marge * $BUYRATE[$j];
$BUYMINBLOCK1 = 1;
$BUYMINBLOCK2 = 1;
# cas de Mexico: achat à la minute indivisible
if (substr($PREFIX[$j], 0, 2) eq "52") {
$BUYMINBLOCK1 = 60;
$BUYMINBLOCK2 = 60;
}
$SELLMINBLOCK1 = 60;
$SELLMINBLOCK2 = 60;
# changement du sellblock pour mobile mahorais
#if (substr($PREFIX[$j], 0, 6) eq "262639") {
# $SELLMINBLOCK1 = 2;
# $SELLMINBLOCK2 = 2;
#}
print FICHIER_CSV_A2B "$PREFIX[$j],$DESTINATION[$j],$SELLRATE,$BUYRATE[$j],$BUYMINBLOCK1,$BUYMINBLOCK2,$SELLMINBLOCK1,$SELLMINBLOCK2\n";
$j++;
}
close FICHIER_CSV;
close FICHIER_CSV_A2B;
system("rm ".$fileRateMvtPre.".csv");
hope this could help