USING THE WHITEPAGES API TO FIND SENIORS

I was doing some telemarketing work lately where I had to call Seniors on the phone every day. I thought it would be interesting to use the WhitePages API to create my own leads. The WhitePages API lets you perform reverse phone look ups, so I wrote a program that generated phone numbers and called the WhitePages API. if the phone number was valid it would create an XML file with info for the phone number; name, address, etc. Unfortunately it didn't yield an age; I just wanted people who were 65+. Fortunately the XML contained the url of a page that supplies age info. Unfortunately I got an HTTP 403 error (access denied) when trying to scan the page with age on it. 

It occurred to me that I could still load these web addresses into a browser and search the browser history for a "65+" string. I did all of this on a PC that was running Windows XP, but Windows XP doesn't let you search browser history. Fortunately Microsoft now has an upgrade for Windows XP that does just that; let's you search browser history (or just about anything else on your PC) - the Desktop Search. So I went to www.microsoft.com, upgraded my PC and was in business.  I wrote some Java routines that did all the work I wanted when following this algorithm I worked out:

(1) Get NPA database from http://www.nanpa.com/area_codes/index.html

It's in MS Access format.

(2) Create npa text file, NPAList.txt, by running query NPAList (database is AllNPAs).

(3) Run WhitePagesAPI (java WhitePagesAPI); produces XML files with file names equal to the phone number they describe.

(4) dir/b NPA* > phoneList.txt create list of valid phone numbers (i.e., the files we have to open up)

(4) Run GetURLStrings (java GetURLStrings); produces urlList (list of url strings so we can can open up the web pages that contain "age" strings)

(5) Run CreateHistory (java CreateHistoryXP); create history files of web pages that contain "age" strings. This program makes a lot of calls on Windows (including IE, kill.exe and tlist.exe utilities).

(6) SearchIE history files files for the string "65+" to get phone numbers for seniors. This requires that Windows Desktop Search and IEHistory add in has been added to the system (for Windows XP; Vista already has this capability).

(7) copy XML files with phone numbers from step 6 to the Seniors folders.

 

In one of my posting I wrote about how much I liked Netbeans 6, which wasn't even in beta at the time I wrote the posting.  To show that Netbeans 6 (I wound up using Netbeans 6.1) could create a nice Swing version of my code, I took all my straight line code and stuck it into the Swing components that Netbeans created. It seems to work. That says loads for Netbeans, because you usually run into serious problems if you code this way. When writing with an IDE like Netbeans you'll have less headaches if you start writing with Netbeans instead of using it as an afterthought. If you write your code using OOD you can probably stick it into an IDE without any trouble, but I wrote this stuff like it was a series of routines written in C. That's why I say that this code working a well as it does says loads for Netbeans. Here's the code from Netbeans. You can create a new project in Netbeans and stick this code into it.

 Return To List Of My Programs

WPAPIApp

/*
* WPAPIApp.java
*/

package wpapi;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
* The main class of the application.
*/
public class WPAPIApp extends SingleFrameApplication {

/**
* At startup create and show the main frame of the application.
*/
@Override protected void startup() {
show(new WPAPIView(this));
}

/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}

/**
* A convenient static getter for the application instance.
* @return the instance of WPAPIApp
*/
public static WPAPIApp getApplication() {
return Application.getInstance(WPAPIApp.class);
}

/**
* Main method launching the application.
*/
public static void main(String[] args) {
launch(WPAPIApp.class, args);
}
}

 

WPAPIView

/*
 * WPAPIView.java
 */
package wpapi;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URL;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
/**
 * The application's main frame.
 */
public class WPAPIView extends FrameView {        
    boolean readyToRecord = false;    
    GetNumbersThread aRunner = new GetNumbersThread();
    Thread MainThread = new Thread(aRunner);       
    public WPAPIView(SingleFrameApplication app) {
        super(app);
        
        initComponents();
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(true);
        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
        statusMessageLabel.setText("Not Ready To Create History");
    }
        
    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = WPAPIApp.getApplication().getMainFrame();
            aboutBox = new WPAPIAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        WPAPIApp.getApplication().show(aboutBox);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        mainPanel = new javax.swing.JPanel();
        AreaCodeLabel = new javax.swing.JLabel();
        ExchangeLabel = new javax.swing.JLabel();
        ExchangeSpinner = new javax.swing.JSpinner();
        AreaCodeSpinner = new javax.swing.JSpinner();
        LineLabel = new javax.swing.JLabel();
        LineSpinner = new javax.swing.JSpinner();
        GetNumbers = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        StatusScreen = new javax.swing.JTextArea();
        StopButton = new javax.swing.JButton();
        HistoryButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(wpapi.WPAPIApp.class).getContext().getResourceMap(WPAPIView.class);
        mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
        mainPanel.setName("mainPanel"); // NOI18N
        AreaCodeLabel.setFont(resourceMap.getFont("AreaCodeLabel.font")); // NOI18N
        AreaCodeLabel.setForeground(resourceMap.getColor("AreaCodeLabel.foreground")); // NOI18N
        AreaCodeLabel.setText(resourceMap.getString("AreaCodeLabel.text")); // NOI18N
        AreaCodeLabel.setName("AreaCodeLabel"); // NOI18N
        ExchangeLabel.setFont(resourceMap.getFont("ExchangeLabel.font")); // NOI18N
        ExchangeLabel.setForeground(resourceMap.getColor("ExchangeLabel.foreground")); // NOI18N
        ExchangeLabel.setText(resourceMap.getString("ExchangeLabel.text")); // NOI18N
        ExchangeLabel.setName("ExchangeLabel"); // NOI18N
        ExchangeSpinner.setFont(resourceMap.getFont("ExchangeSpinner.font")); // NOI18N
        ExchangeSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 999, 1));
        ExchangeSpinner.setName("ExchangeSpinner"); // NOI18N
        AreaCodeSpinner.setFont(resourceMap.getFont("AreaCodeSpinner.font")); // NOI18N
        AreaCodeSpinner.setModel(new javax.swing.SpinnerNumberModel(201, 201, 989, 1));
        AreaCodeSpinner.setName("AreaCodeSpinner"); // NOI18N
        LineLabel.setFont(resourceMap.getFont("LineLabel.font")); // NOI18N
        LineLabel.setForeground(resourceMap.getColor("LineLabel.foreground")); // NOI18N
        LineLabel.setText(resourceMap.getString("LineLabel.text")); // NOI18N
        LineLabel.setName("LineLabel"); // NOI18N
        LineSpinner.setFont(resourceMap.getFont("LineSpinner.font")); // NOI18N
        LineSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 9999, 1));
        LineSpinner.setName("LineSpinner"); // NOI18N
        GetNumbers.setBackground(resourceMap.getColor("GetNumbers.background")); // NOI18N
        GetNumbers.setForeground(resourceMap.getColor("GetNumbers.foreground")); // NOI18N
        GetNumbers.setText(resourceMap.getString("GetNumbers.text")); // NOI18N
        GetNumbers.setName("GetNumbers"); // NOI18N
        GetNumbers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GetNumbersActionPerformed(evt);
            }
        });
        jScrollPane1.setName("jScrollPane1"); // NOI18N
        StatusScreen.setBackground(resourceMap.getColor("StatusScreen.background")); // NOI18N
        StatusScreen.setColumns(20);
        StatusScreen.setRows(5);
        StatusScreen.setName("StatusScreen"); // NOI18N
        jScrollPane1.setViewportView(StatusScreen);
        StopButton.setBackground(resourceMap.getColor("StopButton.background")); // NOI18N
        StopButton.setForeground(resourceMap.getColor("StopButton.foreground")); // NOI18N
        StopButton.setText(resourceMap.getString("StopButton.text")); // NOI18N
        StopButton.setName("StopButton"); // NOI18N
        HistoryButton.setForeground(resourceMap.getColor("HistoryButton.foreground")); // NOI18N
        HistoryButton.setText(resourceMap.getString("HistoryButton.text")); // NOI18N
        HistoryButton.setName("HistoryButton"); // NOI18N
        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(AreaCodeLabel)
                    .addComponent(AreaCodeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 117, Short.MAX_VALUE)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ExchangeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ExchangeLabel))
                .addGap(104, 104, 104)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LineSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LineLabel))
                .addGap(45, 45, 45))
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(68, 68, 68)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(HistoryButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(80, 80, 80)
                .addComponent(GetNumbers)
                .addGap(79, 79, 79)
                .addComponent(StopButton)
                .addContainerGap(169, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LineLabel)
                    .addComponent(ExchangeLabel)
                    .addComponent(AreaCodeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LineSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ExchangeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AreaCodeSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(GetNumbers)
                    .addComponent(StopButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(HistoryButton))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        ExchangeSpinner.setSize(20,100);
        ExchangeSpinner.setSize(20,100);
        HistoryButton.getAccessibleContext().setAccessibleName(resourceMap.getString("HistoryButton.AccessibleContext.accessibleName")); // NOI18N
        menuBar.setName("menuBar"); // NOI18N
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N
        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(wpapi.WPAPIApp.class).getContext().getActionMap(WPAPIView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);
        menuBar.add(fileMenu);
        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N
        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);
        menuBar.add(helpMenu);
        statusPanel.setName("statusPanel"); // NOI18N
        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
        statusMessageLabel.setName("statusMessageLabel"); // NOI18N
        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
        progressBar.setName("progressBar"); // NOI18N
        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 319, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );
        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents
    private void GetNumbersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GetNumbersActionPerformed
       //I originally wrote this as a command line program
       //and wrote it in a procedural fashion which didn't work very well
       //with the swing graphics of Netbeans; the process of getting the XML 
       //pages from the Whitepages web site wound up tight looping. The process
       //of writting to the status screen is done asynchronously, because
       //that's the way Java works, and never get performed because the Java
       //VM is busy tight looping. So I put the main process into a thread and
       //gave it the minimum thread proiority. I also put writes to the status
       //screen in another thread and gave that the highest thread priority; that 
       //worked.       
       MainThread.start();
       //The Stop button has no code behind it. There's no need for hooks until
       //the main process is already running.
       StopButton.addMouseListener(new java.awt.event.MouseAdapter() 
       {
            @Override
            public void mousePressed(java.awt.event.MouseEvent evt) 
            {                
                stop_aThrd(evt);
                if (true)
                {
                   readyToRecord = true;
                   statusMessageLabel.setText("Processing...");
                   MainThread.setName("finis");
        //create a list of found phone numbers
        //at the start of run() we set the name of the thread to "begin" and to "finis" 
        //when we are through processing        
        Integer npaInteger = (Integer) AreaCodeSpinner.getValue();
        int npaInt = npaInteger.intValue();
        String NPA = npaInteger.toString();
        Runtime runtime = Runtime.getRuntime();        
        try
        {                     
           String[] cmd = new String[3];
           cmd[0] = "cmd.exe" ;
           cmd[1] = "/C" ;
           cmd[2] = "dir /b " + NPA + "*" + " > phoneList.txt";
           Process proc = runtime.exec(cmd);
           statusMessageLabel.setText("Phone list created");
        }
        catch (Exception e) 
        {
            statusMessageLabel.setText("Unable to create phone list: " + e.toString());
            try
            {
               Thread.sleep(10000);
            }
            catch(Exception IOEE){}
        }
        //create a list of url strings we can browse to create a history we can search
        statusMessageLabel.setText("Now Creating url list...");
        GetURLStrings urlList = new GetURLStrings();            
        HistoryButton.addMouseListener(new java.awt.event.MouseAdapter() 
        {
            @Override
            public void mousePressed(java.awt.event.MouseEvent evt) 
            {
               CreateHistoryXP hist = new CreateHistoryXP(); 
            }
        });
                }
            }
        });
    }
    
    private void stop_aThrd(java.awt.event.MouseEvent evt) 
    {
    	if (MainThread.isAlive())
	{
            MainThread.stop();            
            MainThread = new Thread(aRunner);  
	}
    }
      class GetNumbersThread implements Runnable
      {
      public void run()
      {
      MainThread.setName("begin");  
      MainThread.setPriority(Thread.MIN_PRIORITY);
      Integer AreaCode = (Integer) AreaCodeSpinner.getValue();
      int AreaCodeInt = AreaCode.intValue();
      Integer Exchange = (Integer) ExchangeSpinner.getValue();
      int ExchangeInt = Exchange.intValue();
      Integer Line = (Integer) LineSpinner.getValue();
      int LineInt = Line.intValue();                     
      DataInputStream in = null;    //ascii character stream for NPAList.txt
      InputStream  whiteIn = null;  //input stream from WhitePages API page
      OutputStream whiteOut = null; //output stream to capture returned XML
      String urlStrFront = "http://api.whitepages.com/reverse_phone/1.0/?phone=";
      String urlStrEnd = ";api_key=aNumberYouGetFromTheWhitePages";
      String phone = null;   
        try
        {
           in = new DataInputStream(new FileInputStream("NPAList.txt"));
           String npa;
           while ((npa = in.readLine())!= null)
           {            
              //DEBUG   just want my area code
              if (AreaCodeInt != Integer.parseInt(npa))
              {               
                 continue;
              }
              //DEBUG
              for (int exNum = ExchangeInt; exNum > 99; exNum--)  //DEBUG was using starting value of 999                                                                                          
              {                        
                  displayMessage msg = new displayMessage("Starting npa-npx: " + npa + "-" + exNum);
                  Thread aThrd = new Thread(msg);
                  aThrd.setPriority(Thread.MAX_PRIORITY);
                  aThrd.start();
                  
                  for (int lineNum = LineInt; lineNum >= 0; lineNum--) //DEBUG was using starting value 9999
                  {                 
                      String exNumStr;
                      String lineNumStr;
                      if (exNum < 10)
                      {                         
                         exNumStr = "00" + exNum;
                      }
                      else if (exNum < 100)
                      {
                         exNumStr = "0" + exNum;
                      }
                      else
                      {
                         exNumStr = Integer.toString(exNum);
                      }
                      if (lineNum < 10)
                      {
                         lineNumStr = "000" + lineNum;
                      }
                      else if (lineNum < 100)
                      {
                         lineNumStr = "00" + lineNum;
                      }
                      else if (lineNum < 1000)
                      {
                         lineNumStr = "0" + lineNum;
                      }
                      else
                      {
                         lineNumStr = Integer.toString(lineNum);
                      }    
                      phone = npa + exNumStr;
                      phone = phone + lineNumStr;  //phone number to check
                      msg = new displayMessage(phone);
                      aThrd = new Thread(msg);
                      aThrd.setPriority(Thread.MAX_PRIORITY);
                      aThrd.start();
                     
                      String urlStr = urlStrFront + phone + urlStrEnd;
                      URL url = null;
                      try
                      {
                         url = new URL(urlStr);   //call to WhitePAges API
                      }
                      catch (IOException IOe)
                      {
                         msg = new displayMessage(IOe.toString());
                         aThrd = new Thread(msg);
                         aThrd.setPriority(Thread.MAX_PRIORITY);
                         aThrd.start();
                                            
                         continue;
                      }
                      try
                      {
                         boolean noname = true;   //set to false if we find a name
                         whiteIn = url.openStream();  //create a stream to it
                         whiteOut = new FileOutputStream(phone); //name XML file the same as the phone number being tested
                         byte[] buffer = new byte[4096];  //will hold XML output
                         int bytes_read;
                         while((bytes_read = whiteIn.read(buffer)) != -1)
                         {
                            String testStr = new String(buffer);
                            if (testStr.indexOf("name") != -1)
                            {
                               noname = false;
                            }
                            whiteOut.write(buffer,0,bytes_read); //write XML                        
                         }
                         whiteIn.close();
                         whiteOut.close();
                         //if there is no string "name" in this file, delete it
                         if (noname)
                         {
                            File f = new File(phone);
                            if (f.exists())
                            {
                               f.delete();
                            }
                            msg = new displayMessage("Just deleted: " + phone);
                            aThrd = new Thread(msg);
                            aThrd.setPriority(Thread.MAX_PRIORITY);
                            aThrd.start();
                            
                         }                        
                      }
                      catch (IOException IOe)
                      {
                         msg = new displayMessage(IOe.toString());                         
                         aThrd = new Thread(msg);
                         aThrd.setPriority(Thread.MAX_PRIORITY);
                         aThrd.start();
                         
                         continue;   //skip to next phone number
                      }
                  }
              }
           }
        }
        catch(IOException e)
        {
           displayMessage msg = new displayMessage("Abend: " + e.toString());
           Thread aThrd = new Thread(msg);
           aThrd.setPriority(Thread.MAX_PRIORITY);
           aThrd.start();                   
          // System.exit(0);
        }
        try
        {
           in.close();
        }
        catch (Exception IOe) {}
        MainThread.setName("finis");
        //create a list of found phone numbers
        //at the start of run() we set the name of the thread to "begin" and to "finis" 
        //when we are through processing        
        Integer npaInteger = (Integer) AreaCodeSpinner.getValue();
        int npaInt = npaInteger.intValue();
        Runtime runtime = Runtime.getRuntime();
        try
        {
           String[] cmd = new String[3];
           cmd[0] = "cmd.exe" ;
           cmd[1] = "/C" ;
           cmd[2] = "dir /b " + npaInt + "*" + " > phoneList.txt";
           Process proc = runtime.exec(cmd);
           statusMessageLabel.setText("Phone list created");
        }
        catch (Exception e) {}
        //create a list of url strings we can browse to create a history we can search
        GetURLStrings urlList = new GetURLStrings();            
        HistoryButton.addMouseListener(new java.awt.event.MouseAdapter() 
        {
            @Override
            public void mousePressed(java.awt.event.MouseEvent evt) 
            {
                if (readyToRecord)
                {
                   CreateHistoryXP hist = new CreateHistoryXP(); 
                }
            }
        });
    }//GEN-LAST:event_GetNumbersActionPerformed
      }
      
    class displayMessage implements Runnable
    {
        String statusMsg = "Latest Message";
        displayMessage(String msg)
        {
            statusMsg = msg + '\n';
        }  
               
        @Override
        public void run()
        {
            StatusScreen.append(statusMsg);                                
        }      
    }
    
class CreateHistoryXP
{
   private void dispARec(String httpStr)
   {
      try
      {
         Runtime runtime = Runtime.getRuntime();
         Process proc = runtime.exec(httpStr);
      }
      catch (Exception e)
      {
         StatusScreen.append("uable to execute " + e.toString() + '\n');
      }
   }
   CreateHistoryXP()
   {
      //Let IE do the work. Every time a browser session is started
      //we get a session file in IE history. We can search these files for
      //the string "65+"
      DataInputStream urlStream = null;
      try
      {
         //string for starting IE
         String browserStr = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
         //string for killing IE
         String killStr = "taskkill /fi \"IMAGENAME eq iexplore*\"";         
         urlStream = new DataInputStream(new FileInputStream("urlList"));
         String urlStr;
         int aChar = 0;
         while ((urlStr = urlStream.readLine()) != null)
         {            
            String httpStr = browserStr + " " + urlStr;
            this.dispARec(httpStr);  //open browser session
            StatusScreen.append("Opening " + urlStr + '\n');
            Thread.sleep(15000);
            this.dispARec(killStr); //kill browser session
            Thread.sleep(5000);
         }
      }
      catch (Exception e)
      {
         StatusScreen.append(e.toString() + '\n');
      }
      if (urlStream != null)
      {
         try
         {
            urlStream.close();
         }
         catch (IOException e){}
      }
   }
}
class GetURLStrings
{
   GetURLStrings()
   {
      String phone;
      try
      {
         statusMessageLabel.setText("In url list creation routine"); 
         DataInputStream phoneStream = new DataInputStream(new FileInputStream("phoneList.txt"));
         PrintStream ostream = new PrintStream(new FileOutputStream("urlList"));
         while ((phone = phoneStream.readLine()) != null)
         {
            if (phone.length() != 10) continue;
            DataInputStream istream = new DataInputStream(new FileInputStream(phone));
            String line = null;
            while ((line = istream.readLine()) != null)
            {
               if ((line.indexOf("<wp:link wp:linktext=\"View Listing Detail\" wp:type=\"viewdetails\">")) != -1)
               {
                  int start = line.indexOf("http");
                  int end   = line.indexOf("</wp:link>");
                  String httpStr = line.substring(start,end);
                  ostream.println(httpStr);
                  break;
               }
            }
            istream.close();
         }
         ostream.close();        
      }
      catch (IOException e)
      {
      }
      readyToRecord = true;
      statusMessageLabel.setText("Ready To Create History");
   }
}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AreaCodeLabel;
    private javax.swing.JSpinner AreaCodeSpinner;
    private javax.swing.JLabel ExchangeLabel;
    private javax.swing.JSpinner ExchangeSpinner;
    private javax.swing.JButton GetNumbers;
    private javax.swing.JButton HistoryButton;
    private javax.swing.JLabel LineLabel;
    private javax.swing.JSpinner LineSpinner;
    private javax.swing.JTextArea StatusScreen;
    private javax.swing.JButton StopButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
}

 

                                                                                           Return To List Of My Programs