#!/usr/bin/perl #* #* GnuDialer - Complete, free predictive dialer #* #* Complete, free predictive dialer for contact centers. #* #* Copyright (C) 2009, GnuDialer Project #* #* Richard Lyman #* #* This program is free software, distributed under the terms of #* the GNU General Public License. #* use DBI; $drh = DBI->install_driver('mysql') or die("Unable to install driver"); $dbh = DBI->connect("DBI:mysql:dialer",'dialer','1234') or die("Unable to connect"); $from = "FR"; $when = "0"; $some_nosales = 0; $some_dncs = 0; &collect_disco(); &what_dbs; #print "\nNosales Exported: " . $fresh . "\n"; system("unix2dos /tmp/" . $from . very_short_stamp() . ".disco"); if ($some_nosales) { system("unix2dos /tmp/" . $from . very_short_stamp() . ".nosale"); }; if ($some_dncs) { system("unix2dos /tmp/" . $from . very_short_stamp() . ".dnc"); }; $dbh->disconnect; #################################################################################################### sub what_dbs { my $ret = 0; my $sth = $dbh->prepare("SHOW TABLES"); $sth->execute or print "query: what_dbs failed"; while(@table = $sth->fetchrow_array) { if ($table[0] ne 'BLACKLIST' && $table[0] ne 'INBOUND' && $table[0] ne 'CLOSER' && $table[0] ne 'DISCO' && $table[0] ne 'cdr' && $table[0] ne 'CDR' && $table[0] ne 'dnc' && $table[0] ne 'DNC') { #print $table[0] . "\n"; # to screen find_nosales($table[0]); find_donotcalls($table[0]); } } $sth->finish; return $ret; } #################################################################################################### sub find_nosales { local($thetable) = @_; my $ret = 0; my $sth = $dbh->prepare("SELECT phone FROM " . $thetable . " WHERE disposition = '11' AND (LEFT(lastupdated,10) = DATE_ADD(CURDATE(), INTERVAL " . $when . " DAY))"); $sth->execute or print "query: what_dbs failed"; while(@rec = $sth->fetchrow_array) { #print "" . $rec[0] . "\n"; # to screen dump_nosales($rec[0],"nosale"); # to file $some_nosales++; } $sth->finish; return $ret; } #################################################################################################### sub find_donotcalls { local($thetable) = @_; my $ret = 0; my $sth = $dbh->prepare("SELECT phone FROM " . $thetable . " WHERE disposition = '8' AND (LEFT(lastupdated,10) = DATE_ADD(CURDATE(), INTERVAL " . $when . " DAY))"); $sth->execute or print "query: what_dbs failed"; while(@rec = $sth->fetchrow_array) { #print "" . $rec[0] . "\n"; # to screen dump_donotcalls($rec[0],"dnc"); # to file $some_dncs++; } $sth->finish; return $ret; } ################################################################################################### # YYYYMMDD datestamp sub short_stamp { ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = (localtime(time))[0,1,2,3,4,5,6,7,8]; $mydatetimestamp = sprintf("%4.4d%2.2d%2.2d", $year+1900, $month+1, $mday); return $mydatetimestamp } ################################################################################################### # YYYYMMDD datestamp sub very_short_stamp { ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = (localtime(time))[0,1,2,3,4,5,6,7,8]; $mydatetimestamp = sprintf("%02d%02d%02d", $year-100, $month+1, $mday); return $mydatetimestamp } ################################################################################################### sub dump_nosales { my ($o_phone, $ftype) = @_; my $outdir = '/tmp'; my $filename = $outdir . '/' . $from . very_short_stamp() . '.' . $ftype; if ($some_nosales) { open(OUTFILE, ">>$filename") || return 0; } else { open(OUTFILE, ">$filename") || return 0; } flock(OUTFILE, LOCK_EX); #print OUTFILE "\"" . $o_phone . "\"\n"; print OUTFILE "" . $o_phone . "\n"; flock(OUTFILE, LOCK_UN); close(OUTFILE); return 1; } ################################################################################################### sub dump_donotcalls { my ($o_phone, $ftype) = @_; my $outdir = '/tmp'; my $filename = $outdir . '/' . $from . very_short_stamp() . '.' . $ftype; if ($some_dncs) { open(OUTFILE, ">>$filename") || return 0; } else { open(OUTFILE, ">$filename") || return 0; } flock(OUTFILE, LOCK_EX); #print OUTFILE "\"" . $o_phone . "\"\n"; print OUTFILE "" . $o_phone . "\n"; flock(OUTFILE, LOCK_UN); close(OUTFILE); return 1; } ################################################################################################### sub collect_disco { system("grep -hor \"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] Reason: 0\" /var/log/asterisk/messages >/tmp/tmpdisco.txt"); system("grep -hor \"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\" /tmp/tmpdisco.txt >/tmp/" . $from . very_short_stamp() . ".disco"); }