Java Reference
In-Depth Information
pw
.
println
(
date
+
" "
+
rank
);
pw
.
close
();
String gnuplot_cmd
=
"set term png\n"
+
"set output \""
+
GRAPH_FILE
+
"\"\n"
+
"set xdata time\n"
+
"set ylabel \"Book sales rank\"\n"
+
"set bmargin 3\n"
+
"set logscale y\n"
+
"set yrange [1:60000] reverse\n"
+
"set timefmt \"%m %d %H %M %S %Y\"\n"
+
"plot \""
+
DATA_FILE
+
"\" using 1:7 title \""
+
title
+
"\" with lines\n"
;
iif
(!
new
new
File
(
PLOTTER_PROG
).
exists
()) {
System
.
out
.
println
(
"Plotting software not installed"
);
return
return
;
}
Process proc
=
Runtime
.
getRuntime
().
exec
(
PLOTTER_PROG
);
PrintWriter gp
=
new
new
PrintWriter
(
proc
.
getOutputStream
());
gp
.
print
(
gnuplot_cmd
);
gp
.
close
();
}
/**
* Look for something like this in the HTML input:
* <b>Sales Rank:</b>
* #26,252
* </font><br>
* @throws IOException
* @throws IOException
*/
public
public static
static
int
int
getBookRank
(
String isbn
)
throws
throws
IOException
{
// The RE pattern - digits and commas allowed
final
final
String pattern
=
"Rank:</b> #([\\d,]+)"
;
final
final
Pattern r
=
Pattern
.
compile
(
pattern
);
// The url -- must have the "isbn=" at the very end, or otherwise
// be amenable to being appended to.
final
final
String url
=
"http://www.amazon.com/exec/obidos/ASIN/"
+
isbn
;
// Open the URL and get a Reader from it.
final
final
BufferedReader is
=
new
new
BufferedReader
(
new
new
InputStreamReader
(