String response = FileTools.getFileContentsAsString(cacheFile);
if (response == null) {
response = WebTools.getURLAsString(url);
file(cacheFile, response);
}
Event event = new Event();
event.setName(getTableValue("Name", response));
event.setPoints(Integer.parseInt(getTableValue("Point Value", response)));
String colNumber = getTableValue("Collector's Number", response);
String number = colNumber;
if (number.indexOf("-") > 0) {
int base = -1;
if (number.startsWith("PS")) {
base = 0;
}
if (number.startsWith("ES")) {
base = 40;
}
if (number.startsWith("SS")) {
base = 68;
}
String remainder = number.substring(number.indexOf("-") + 1);
if (base >= 0) {
number = "" + (Integer.parseInt(remainder) + base);
}
}
event.setNumber(number);
event.setExtra(colNumber);
event.setRarity(getTableValue("Rarity", response));
String marker = "<td><strong>";
if (response.indexOf(marker) > -1) {
int start = response.indexOf(marker);
int end = response.indexOf("</td>", start);
String cell = response.substring(start + 12, end - 4);
cell = cell.trim();
cell = cell.replaceAll("<P>", "<p>");
cell = cell.replaceAll("</strong>", "");
cell = cell.replaceAll("^ *<p>", "");
cell = cell.trim();
cell = cell.replaceAll("^<p>", "");
String[] parts = cell.trim().split("<p>");
if (parts.length == 1) {
event.setFlavor("");
event.setRules(parts[0].trim());
} else {
event.setRules(fixRules(parts[0].trim()));
event.setFlavor(parts[1].trim());
}
}
if (response.indexOf("src=\"images/Release") > -1) {
int start = response.indexOf("src=\"images/Release");
int end = response.indexOf("width", start);
String set = response.substring(start, end);
set = set.replaceAll(".*alt=\"(.*)\"", "$1");
event.setExpansion(set.trim());
}
if (response.indexOf("src=\"images/faction") > -1) {
int start = response.indexOf("src=\"images/faction");
int end = response.indexOf("width", start);
String faction = response.substring(start, end);
faction = faction.replaceAll(".*alt=\"(.*)\"", "$1");
event.setFaction(faction.trim());
}
return event;
}