VICIDIAL test lead generator

Discussions about development of VICIDIAL and astGUIclient

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

VICIDIAL test lead generator

Postby mcargile » Sun Jan 21, 2007 1:29 pm

I wrote this bash script to generate random test leads for VICIDIAL and insert them into the DB. Currently it needs to be run on the system hosting the DB. When I get some free time I plan to add an option to connect to the DB remotely.

It normally generates 555 numbers (in asterisk the NXX55501XX range) which should be fake numbers under NANP. With the -r option it will create real numbers under NANP (be careful with this option as there is no Do-Not-Call srubbing in the script). It also checks that the phone number is not in the Caribbean, Canada, or a 900 number.

Currently it creates a temporary file to hold the SQL insert statements so that only one DB connection needs to be opened, which is why it limits you to 100000 leads. I do not know of any way to get around this in bash. I may redo this in perl if I find myself with a bunch of free time on my hands so as to overcome this.

Be very careful how you use this script. If you choose to use it, I am not responcible for any charges on your phone bill, or fines that you incure. I plan on using this on a test dialer that is hooked up to a second asterisk box that fakes the phone system.

ranlead.sh:
Code: Select all
#!/bin/bash


# ranlead.sh VERSION 0.3
#
# Inserts into VICIDIAL leads with a random phone number
#
# Copyright (C) 2007  Michael Cargile, Explido Software USA, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


# Because this script creates a temp file to hold the sql statements before
# running them against the DB there is a max lead constraint to prevent the
# temp file from getting huge. This can be overridden if desired with the -M
# option. Just ask yourself though "Do I need really more than 100000 leads
# for test purposes?"
MAXLEADS=100000
DATE=`date +%G-%m-%d`
FILE="/tmp/`basename $0``date +%s`"
VERSION="0.3"

NUMLEADS=""
USER=""
PASSWORD=""
LISTID=""
REALLEADS="FALSE"
HELP="FALSE"
VERBOSE="FALSE"
ALLOWPASTMAX="FALSE"

while getopts ":n:u:p:l:rhvM" Option
do
   case $Option in
      n)   NUMLEADS=$OPTARG;;
      u)   USER=$OPTARG;;
      p)   PASSWORD=$OPTARG;;
      l)   LISTID=$OPTARG;;
      r)   REALLEADS="TRUE";;
      h)   HELP="TRUE";;
      v)   VERBOSE="TRUE";;
      M)   ALLOWPASTMAX="TRUE";;
   esac
done

shift $(($OPTIND - 1))

if [ "$HELP" == "TRUE" ]
then
   echo "`basename $0` version $VERSION"
   echo "Usage: `basename $0` options (-nMuplrhv)"
   echo "-nNUMLEADS where NUMLEADS is the number of leads"
   echo "-M is switch to allow more than $MAXLEADS leads to be generated (may cause problems)"
   echo "-uDBUSERNAME where DBUSERNAME is the username for the VICIDIAL DB"
   echo "-pDBPASSWORD where DBPASSWORD is the password for the VICIDIAL DB"
   echo "-lLISTID where LISTID is the id of the list you are creating"
   echo "-r is a switch to create real numbers instead of 555 numbers"
   echo "-h displays this help message"
   echo "-v switches on verbose mode"
   exit 0
fi

if [[ "$ALLOWPASTMAX" == "FALSE" && "$NUMLEADS" -ge $MAXLEADS ]]
then
   echo "TOO MANY LEADS REQUESTED"
   echo "use -M if you wish to go past $MAXLEADS"
   echo "USE -M AT YOUR OWN RISK"
   exit 1
fi

if [ "$ALLOWPASTMAX" == "TRUE" ]
then
   echo "ALLOWPASTMAX is enabled!!!"
   echo "Good luck."
fi

if [ "$NUMLEADS" == "" ]
then
   #get the number of leads
   echo -n "Enter number of leads: "
   read NUMLEADS
fi

if [ "$LISTID" == "" ]
then
   #get list id for this list
   echo -n "Enter the list id: "
   read LISID
fi

if [ "$USER" == "" ]
then
   #get the username to connect to the DB
   echo -n "Enter DB username: "
   read USER
fi

if [ "$PASSWORD" == "" ]
then
   #get the password to connect to the DB
   echo -n "Enter DB password: "
   read -s PASSWORD #-s to hide the output
   echo ""
fi

if [ "$VERBOSE" == "TRUE" ]
then
   echo ""
   echo -n "Generating leads."
fi

COUNT=1
NUMBER=0
REST=0
ADDITION=0
AREACODE=0

while [ "$COUNT" -le $NUMLEADS ]
do
   if [ "$VERBOSE" == "TRUE" ]
   then
      echo -n "."
   fi

   let "COUNT += 1"
   
   # make sure we are not calling the carribiean, canada, or 900 numbers
   BADAREA="TRUE"
   while [ "$BADAREA" == "TRUE" ]
   do
      AREACODE=$RANDOM
      let "AREACODE %= 800"
      let "AREACODE += 200"
      case $AREACODE in
         809)   BADAREA="TRUE";; # Carribiean
         441)   BADAREA="TRUE";;
         787)   BADAREA="TRUE";;
         340)   BADAREA="TRUE";;
         670)   BADAREA="TRUE";;
         671)   BADAREA="TRUE";;
         939)   BADAREA="TRUE";;
         684)   BADAREA="TRUE";;
         403)   BADAREA="TRUE";; # Canada
         780)   BADAREA="TRUE";;
         204)   BADAREA="TRUE";;
         709)   BADAREA="TRUE";;
         289)   BADAREA="TRUE";;
         416)   BADAREA="TRUE";;
         519)   BADAREA="TRUE";;
         613)   BADAREA="TRUE";;
         647)   BADAREA="TRUE";;
         705)   BADAREA="TRUE";;
         807)   BADAREA="TRUE";;
         905)   BADAREA="TRUE";;
         306)   BADAREA="TRUE";;
         250)   BADAREA="TRUE";;
         604)   BADAREA="TRUE";;
         778)   BADAREA="TRUE";;
         506)   BADAREA="TRUE";;
         902)   BADAREA="TRUE";;
         418)   BADAREA="TRUE";;
         450)   BADAREA="TRUE";;
         514)   BADAREA="TRUE";;
         819)   BADAREA="TRUE";;
         867)   BADAREA="TRUE";;
         900)   BADAREA="TRUE";; # toll numbers
         *)   BADAREA="FALSE";;
      esac
   done

   ADDITION=$RANDOM
   if [ "$REALLEADS" == "FALSE" ]
   then
      #5550100 through 5550199 are fictitious
      REST="5550100"
      let "ADDITION %= 100"
      let "REST += ADDITION"
      NUMBER="$AREACODE$REST"
   else   
      #2000000 through 9999999 are real excluding 5550100 through 5550199
      NUMBER="5550100"
      while [[ "$NUMBER" -ge "5550100" && "$NUMBER" -le "5550199" ]]
      do
         REST="2000000"
         let "ADDITION %= 8000000"
         let "REST += ADDITION"
         NUMBER="$AREACODE$REST"
      done
   fi
   
   echo "insert into asterisk.vicidial_list values('','$DATE','','NEW','','','TEST01','$LISTID','TESTCAMP','N','1','$NUMBER','Mr','JOHN','H','SMITH-$COUNT','$RANDOM Fake St.','','','Clearwater','FL','','33760','USA','M','1970-01-01','','test@test.com','suprise','comments go here','0');" >> $FILE
done

if [ "$VERBOSE" == "TRUE" ]
then
   echo ""
   echo ""
   echo "Inserting leads into the database."
fi

mysql -u $USER --password=$PASSWORD -e "\. $FILE"

if [ "$VERBOSE" == "TRUE" ]
then
   echo "Cleaning up."
fi

rm $FILE



If anyone can see some areas of improvement, or can think of any other area codes that are not a wise idea to dial within the US, please let me know.
Last edited by mcargile on Mon Aug 20, 2007 11:58 am, edited 2 times in total.
Michael Cargile | Director of Engineering | ViciDialGroup | http://www.vicidial.com

The official source for VICIDIAL services and support. 1-888-894-VICI (8424)
mcargile
Site Admin
 
Posts: 617
Joined: Tue Jan 16, 2007 9:38 am

Postby mflorell » Sun Jan 21, 2007 3:21 pm

Thanks for posting this, as for area code lists, there is one included in the release of astguiclient that is loaded into the phon_codes table.

Could you possibly post this to the tracker too?
mflorell
Site Admin
 
Posts: 18387
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby mcargile » Mon Jan 22, 2007 11:27 am

I am currently adding a few more features mainly remote DB connect, duplicate checking, and getting the rest of the bad area codes in. Once I am done I will submit it to the tracker.
Last edited by mcargile on Mon Aug 20, 2007 11:59 am, edited 1 time in total.
Michael Cargile | Director of Engineering | ViciDialGroup | http://www.vicidial.com

The official source for VICIDIAL services and support. 1-888-894-VICI (8424)
mcargile
Site Admin
 
Posts: 617
Joined: Tue Jan 16, 2007 9:38 am

Postby mcargile » Tue Jan 30, 2007 3:03 pm

Finally got around to working on this again. When I look in the vicidial_phone_codes table there is nothing.

Code: Select all
mysql> select * from vicidial_phone_codes;
Empty set (0.00 sec)


However I looked in phone_codes_GMT.txt and found a number of them. I also put in checks to ensure that leads created within New York State do not use exchanges that change tolls "540 550 900 970 976". Here is what I have:

Code: Select all
#!/bin/bash

###################################################################################
#                                                                                 #
# ranlead.sh VERSION 0.6                                                          #
#                                                                                 #
# Inserts into VICIDIAL leads with a random phone number in the USA               #
#                                                                                 #
# Copyright (C) 2007  Michael Cargile, Explido Software USA, Inc.                 #
#                                                                                 #
# This program is free software; you can redistribute it and/or                   #
# modify it under the terms of the GNU General Public License                     #
# as published by the Free Software Foundation; either version 2                  #
# of the License, or (at your option) any later version.                          #
#                                                                                 #
# This program is distributed in the hope that it will be useful,                 #
# but WITHOUT ANY WARRANTY; without even the implied warranty of                  #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   #
# GNU General Public License for more details.                                    #
#                                                                                 #
# You should have received a copy of the GNU General Public License               #
# along with this program; if not, write to the Free Software                     #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. #
#                                                                                 #
###################################################################################

# constants:
# Because this script creates a temp file to hold the sql statements before
# running them against the DB there is a max lead constraint to prevent the
# temp file from getting huge. This can be overridden if desired with the -M
# option. Just ask yourself though "Do I need really more than 100000 leads
# for test purposes?"
MAXLEADS=100000
DATE=`date +%G-%m-%d`
FILE="/tmp/`basename $0``date +%s`"
VERSION="0.6"

# options:
NUMLEADS=""
USER=""
PASSWORD=""
LISTID=""
REALLEADS="FALSE"
HELP="FALSE"
VERBOSE="FALSE"
ALLOWPASTMAX="FALSE"
DUPCHECK="FALSE"
WARNING="TRUE"
DBSERVER="localhost"

while getopts ":n:u:p:l:s:rhvMDW" Option
do
   case $Option in
      n)   NUMLEADS=$OPTARG;;
      u)   USER=$OPTARG;;
      p)   PASSWORD=$OPTARG;;
      l)   LISTID=$OPTARG;;
      s)   DBSERVER=$OPTARG;;
      r)   REALLEADS="TRUE";;
      h)   HELP="TRUE";;
      v)   VERBOSE="TRUE";;
      M)   ALLOWPASTMAX="TRUE";;
      D)   DUPCHECK="TRUE";;
      W)   WARNING="FALSE"
   esac
done

shift $(($OPTIND - 1))
if [ "$WARNING" == "TRUE" ]
then
   echo "#################################################################################"
   echo "# WARNING!!!!                                                                   #"
   echo "# I do my best in this script ensure that the numbers it creates are within the #"
   echo "# USA and not toll numbers. However I cannot guarantee this. If you choose to   #"
   echo "# actually dial these leads, you do so at your own risk.                        #"
   echo "#################################################################################"
   echo ""
fi

if [ "$HELP" == "TRUE" ]
then
   echo "`basename $0` version $VERSION"
   echo "Usage: `basename $0` options (-nMuplrhvDs)"
   echo "-n NUMLEADS where NUMLEADS is the number of leads"
   echo "-M is a switch to allow more than $MAXLEADS leads to be generated (may cause problems)"
   echo "-D is a switch to enable duplicate checking"
   echo "-u DBUSERNAME where DBUSERNAME is the username for the VICIDIAL DB"
   echo "-p DBPASSWORD where DBPASSWORD is the password for the VICIDIAL DB"
   echo "-l LISTID where LISTID is the id of the list you are creating"
   echo "-s DBSERVER where DBSERVER is the hostname of the VIDIDAIL DB"
   echo "-r is a switch to create real numbers instead of 555 numbers"
   echo "-h displays this help message"
   echo "-v switches on verbose mode"
   echo "-W disables the warning message"
   exit 0
fi

if [[ "$ALLOWPASTMAX" == "FALSE" && "$NUMLEADS" -ge $MAXLEADS ]]
then
   echo "TOO MANY LEADS REQUESTED"
   echo "use -M if you wish to go past $MAXLEADS"
   echo "USE -M AT YOUR OWN RISK"
   exit 1
fi

if [ "$ALLOWPASTMAX" == "TRUE" ]
then
   echo "ALLOWPASTMAX is enabled!!!"
   echo "Good luck."
fi

if [ "$NUMLEADS" == "" ]
then
   #get the number of leads
   echo -n "Enter number of leads: "
   read NUMLEADS
fi

if [ "$LISTID" == "" ]
then
   #get list id for this list
   echo -n "Enter the list id: "
   read LISID
fi

if [ "$USER" == "" ]
then
   #get the username to connect to the DB
   echo -n "Enter DB username: "
   read USER
fi

if [ "$PASSWORD" == "" ]
then
   #get the password to connect to the DB
   echo -n "Enter DB password: "
   read -s PASSWORD #-s to hide the output
   echo ""
fi

if [ "$VERBOSE" == "TRUE" ]
then
   echo ""
   echo -n "Generating leads."
fi

COUNT=1
NUMBER=0
REST=0
ADDITION=0
AREACODE=0

touch $FILE

while [ "$COUNT" -le $NUMLEADS ]
do
   if [ "$VERBOSE" == "TRUE" ]
   then
      echo -n "."
   fi

   # make sure we are not calling the carribiean, canada, or 900 numbers
      BADAREA="TRUE"
   while [ "$BADAREA" == "TRUE" ]
   do
      AREACODE=$RANDOM
      let "AREACODE %= 800"
      let "AREACODE += 200"
      case $AREACODE in
         297)   BADAREA="TRUE";; # Carribiean
         264)   BADAREA="TRUE";; # Carribiean
         599)   BADAREA="TRUE";; # Carribiean
         684)   BADAREA="TRUE";; # Carribiean
         268)   BADAREA="TRUE";; # Carribiean
         242)   BADAREA="TRUE";; # Carribiean
         441)   BADAREA="TRUE";; # Carribiean
         246)   BADAREA="TRUE";; # Carribiean
         345)   BADAREA="TRUE";; # Carribiean
         767)   BADAREA="TRUE";; # Carribiean
         809)   BADAREA="TRUE";; # Carribiean
         590)   BADAREA="TRUE";; # Carribiean
         473)   BADAREA="TRUE";; # Carribiean
         671)   BADAREA="TRUE";; # Carribiean
         876)   BADAREA="TRUE";; # Carribiean
         869)   BADAREA="TRUE";; # Carribiean
         758)   BADAREA="TRUE";; # Carribiean
         670)   BADAREA="TRUE";; # Carribiean
         664)   BADAREA="TRUE";; # Carribiean
         596)   BADAREA="TRUE";; # Carribiean
         787)   BADAREA="TRUE";; # Carribiean
         649)   BADAREA="TRUE";; # Carribiean
         868)   BADAREA="TRUE";; # Carribiean
         784)   BADAREA="TRUE";; # Carribiean
         284)   BADAREA="TRUE";; # Carribiean
         340)   BADAREA="TRUE";; # Carribiean
         204)   BADAREA="TRUE";; # Canada
         226)   BADAREA="TRUE";; # Canada
         250)   BADAREA="TRUE";; # Canada
         289)   BADAREA="TRUE";; # Canada
         306)   BADAREA="TRUE";; # Canada
         403)   BADAREA="TRUE";; # Canada
         416)   BADAREA="TRUE";; # Canada
         418)   BADAREA="TRUE";; # Canada
         438)   BADAREA="TRUE";; # Canada
         450)   BADAREA="TRUE";; # Canada
         506)   BADAREA="TRUE";; # Canada
         514)   BADAREA="TRUE";; # Canada
         519)   BADAREA="TRUE";; # Canada
         604)   BADAREA="TRUE";; # Canada
         613)   BADAREA="TRUE";; # Canada
         647)   BADAREA="TRUE";; # Canada
         705)   BADAREA="TRUE";; # Canada
         709)   BADAREA="TRUE";; # Canada
         778)   BADAREA="TRUE";; # Canada
         780)   BADAREA="TRUE";; # Canada
         807)   BADAREA="TRUE";; # Canada
         819)   BADAREA="TRUE";; # Canada
         867)   BADAREA="TRUE";; # Canada
         902)   BADAREA="TRUE";; # Canada
         905)   BADAREA="TRUE";; # Canada
         900)   BADAREA="TRUE";; # toll numbers
         *)   BADAREA="FALSE";; # everything else
      esac
   done

   ADDITION=$RANDOM
   if [ "$REALLEADS" == "FALSE" ]
   then
      #5550100 through 5550199 are fictitious
      REST="5550100"
      let "ADDITION %= 100"
      let "REST += ADDITION"
      NUMBER="$AREACODE$REST"
   else   
      #2000000 through 9999999 are real excluding 5550100 through 5550199
      NUMBER="5550100"
      # NEW YORK has exchanges that act as TOLL numbers
      INNEWYORK="TRUE"
      case $AREACODE in
         212)   INNEWYORK="TRUE";;
         315)   INNEWYORK="TRUE";;
         347)   INNEWYORK="TRUE";;
         516)   INNEWYORK="TRUE";;
         518)   INNEWYORK="TRUE";;
         585)   INNEWYORK="TRUE";;
         607)   INNEWYORK="TRUE";;
         631)   INNEWYORK="TRUE";;
         646)   INNEWYORK="TRUE";;
         716)   INNEWYORK="TRUE";;
         718)   INNEWYORK="TRUE";;
         845)   INNEWYORK="TRUE";;
         914)   INNEWYORK="TRUE";;
         917)   INNEWYORK="TRUE";;
         *)   INNEWYORK="FALSE";;
      esac
      while [[ "$NUMBER" -ge "5550100" && "$NUMBER" -le "5550199" ]]
      do
         BADEXCHANGE="TRUE"
         while [[ "$BADEXCHANGE" == "TRUE" ]]
         do
            BADEXCHANGE="FALSE"
            EXCHANGE="200"
            let "ADDITION %= 800"
            let "EXCHANGE += ADDITION"
            #check to see if this is a bad exchange
            if [[ "$INNEWYORK" == "TRUE" ]]
            then
               case $EXCHANGE in
                  540)   BADEXCHANGE="TRUE";;
                  550)   BADEXCHANGE="TRUE";;
                  900)   BADEXCHANGE="TRUE";;
                  970)   BADEXCHANGE="TRUE";;
                  976)   BADEXCHANGE="TRUE";;
                  *)   BADEXCHANGE="FALSE";;
               esac
            fi
         done
         # GRUMBLE GRUMBLE stupid bash string/number handling
         # need "0000" through "9999" not 0 through 9999
         DIGIT1="$RANDOM"
         DIGIT2="$RANDOM"
         DIGIT3="$RANDOM"
         DIGIT4="$RANDOM"
         let "DIGIT1 %= 10"
         let "DIGIT2 %= 10"
         let "DIGIT3 %= 10"
         let "DIGIT4 %= 10"
         NUMBER="$AREACODE$EXCHANGE$DIGIT1$DIGIT2$DIGIT3$DIGIT4"
      done
   fi

   if [[ "$DUPCHECK" == "TRUE" ]]
   then
      DUPCOUNT=`grep -c $NUMBER $FILE`
      if [[ "$DUPCOUNT" -eq "0" ]]
      then
         echo "insert into asterisk.vicidial_list values('','$DATE','','NEW','','','TEST01','$LISTID','TESTCAMP','N','1','$NUMBER','Mr','JOHN','H','SMITH-$COUNT','$RANDOM Fake St.','','','Clearwater','FL','','33760','USA','M','1970-01-01','','test@test.com','suprise','comments go here','0');" >> $FILE
         let "COUNT += 1"
      fi
   else
      echo "insert into asterisk.vicidial_list values('','$DATE','','NEW','','','TEST01','$LISTID','TESTCAMP','N','1','$NUMBER','Mr','JOHN','H','SMITH-$COUNT','$RANDOM Fake St.','','','Clearwater','FL','','33760','USA','M','1970-01-01','','test@test.com','suprise','comments go here','0');" >> $FILE
      let "COUNT += 1"
   fi
done

if [ "$VERBOSE" == "TRUE" ]
then
   echo ""
   echo ""
   echo "Inserting leads into the database."
fi

mysql --host=$DBSERVER -u $USER --password=$PASSWORD -e "\. $FILE"

if [ "$VERBOSE" == "TRUE" ]
then
   echo "Cleaning up."
fi

rm $FILE


I am now going to post this to the tracker
Last edited by mcargile on Mon Aug 20, 2007 11:59 am, edited 1 time in total.
Michael Cargile | Director of Engineering | ViciDialGroup | http://www.vicidial.com

The official source for VICIDIAL services and support. 1-888-894-VICI (8424)
mcargile
Site Admin
 
Posts: 617
Joined: Tue Jan 16, 2007 9:38 am

Postby mflorell » Wed Jan 31, 2007 4:49 pm

mcargile wrote:Finally got around to working on this again. When I look in the vicidial_phone_codes table there is nothing.

Code: Select all
mysql> select * from vicidial_phone_codes;
Empty set (0.00 sec)




I guess you weren't following the SCRATCH_INSTALL then :)


I am now going to post this to the tracker


Thank you very much!
mflorell
Site Admin
 
Posts: 18387
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby mcargile » Wed Jan 31, 2007 6:11 pm

I guess you weren't following the SCRATCH_INSTALL then :)


HA, thanks. I missed the ADMIN_area_code_populate.pl step on the test dialer. I knew something was fishy. Kind of glad I have not put this dialer into production.
Michael Cargile | Director of Engineering | ViciDialGroup | http://www.vicidial.com

The official source for VICIDIAL services and support. 1-888-894-VICI (8424)
mcargile
Site Admin
 
Posts: 617
Joined: Tue Jan 16, 2007 9:38 am


Return to Development

Who is online

Users browsing this forum: No registered users and 27 guests