Support A2Billing :

provided by Star2Billing S.L.

Support A2Billing :
It is currently Mon May 27, 2019 12:15 pm
VoIP Billing solution


All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Script to import rates from MVT site to CSV file
PostPosted: Tue Jun 12, 2012 9:50 pm 
Offline

Joined: Fri Dec 17, 2010 12:17 pm
Posts: 20
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.htm

and 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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 
Voice Broadcast System


All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group