package org.htmlparser;
import org.htmlparser.beans.StringBean;
import java.util.regex.*;
import java.util.Formatter;
import java.util.Locale;
import java.lang.String;
import java.util.Calendar;
public class StockMonitor2
{
public static void main (String[] args)
{
if (args.length < 3 )
{
System.out.println (“Syntax : java -classpath ../lib/htmlparser.jar id maxprice min”);
}
else
{
try
{
Integer stock_id = new Integer(args[0]);
Float stock_price = new Float(args[1]);
Float stock_price2 = new Float(args[2]);
StringBean se;
se = new StringBean();
se.setLinks(false);
//StringBuilder sb = new StringBuilder();
//formatter.format(“%4$2s %3$2s %2$2s %1$2s”, “a”, “b”, “c”, “d”)
Locale l = null;
String sUrl = String.format(l, “http://www.aastocks.com/eng/StockQuote/default.asp?symbol=%04d”,stock_id.intValue());
se.setURL(sUrl);
//System.out.println(se.getStrings());
Pattern pattern = Pattern.compile(“Bid[\r\n \t]+([0-9.]+)”);
Matcher matcher = pattern.matcher(se.getStrings());
//Calendar rightNow = Calendar.getInstance();
//System.out.println(“monitor time: ” + rightNow.get(Calendar.HOUR_OF_DAY) + “:” +
// rightNow.get(Calendar.MINUTE) + “:” +rightNow.get(Calendar.SECOND));
if (matcher.find())
{
StringBuffer sBuffer = new StringBuffer(matcher.group());
Float now_price = new Float(sBuffer.substring(4));
if (now_price.compareTo(stock_price)>0 || now_price.compareTo(stock_price2)<0)
{
System.out.println(“
“);
}
}
else
{
System.err.println(“can’t match data:\n” + se.getStrings());
}
}
catch (NumberFormatException e)
{
e.printStackTrace();
}
}
}
}