use of org.magic.api.beans.CardShake in project MtgDesktopCompanion by nicho92.
the class MTGPriceDashBoard method getShakeForEdition.
@Override
public List<CardShake> getShakeForEdition(MagicEdition edition) throws IOException {
String name = convert(edition.getSet()).replaceAll(" ", "_");
String url = "http://www.mtgprice.com/spoiler_lists/" + name;
logger.debug("get Prices for " + name + " " + url);
Document doc = Jsoup.connect(url).userAgent(getString("USER_AGENT")).timeout(Integer.parseInt(getString("TIMEOUT"))).get();
Element table = doc.getElementsByTag("body").get(0).getElementsByTag("script").get(2);
List<CardShake> list = new ArrayList<>();
String data = table.html();
data = data.substring(data.indexOf('['), data.indexOf(']') + 1);
JsonElement root = new JsonParser().parse(data);
JsonArray arr = root.getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
JsonObject card = arr.get(i).getAsJsonObject();
CardShake shake = new CardShake();
shake.setName(card.get("name").getAsString());
shake.setEd(edition.getId());
shake.setPrice(card.get("fair_price").getAsDouble());
try {
shake.setPercentDayChange(card.get("percentageChangeSinceYesterday").getAsDouble());
} catch (Exception e) {
MTGLogger.printStackTrace(e);
}
try {
shake.setPercentWeekChange(card.get("percentageChangeSinceOneWeekAgo").getAsDouble());
} catch (Exception e) {
MTGLogger.printStackTrace(e);
}
shake.setPriceDayChange(card.get("absoluteChangeSinceYesterday").getAsDouble());
shake.setPriceWeekChange(card.get("absoluteChangeSinceOneWeekAgo").getAsDouble());
list.add(shake);
}
return list;
}
use of org.magic.api.beans.CardShake in project MtgDesktopCompanion by nicho92.
the class MTGPriceDashBoard method getShakerFor.
@Override
public List<CardShake> getShakerFor(String gameFormat) throws IOException {
List<CardShake> list = new ArrayList<>();
String url = getString("WEBSITE") + "/taneLayout/mtg_price_tracker.jsp?period=" + getString("PERIOD");
Document doc = Jsoup.connect(url).userAgent(getString("USER_AGENT")).timeout(Integer.parseInt(getString("TIMEOUT"))).get();
try {
logger.debug("Get Shake for " + url);
String date = doc.getElementsByClass("span6").get(1).text().replaceAll("Updated:", "").replaceAll("UTC ", "").trim();
SimpleDateFormat forma = new SimpleDateFormat("E MMMM dd hh:mm:ss yyyy", Locale.ENGLISH);
updateTime = forma.parse(date);
} catch (ParseException e1) {
logger.error(e1);
}
if (gameFormat.equalsIgnoreCase("STANDARD"))
gameFormat = "Standard";
else if (gameFormat.equalsIgnoreCase("MODERN"))
gameFormat = "Modern";
else if (gameFormat.equalsIgnoreCase("VINTAGE"))
gameFormat = "Vintage";
else if (gameFormat.equalsIgnoreCase("LEGACY"))
gameFormat = "All";
Element table = doc.getElementById("top50" + gameFormat);
Element table2 = doc.getElementById("bottom50" + gameFormat);
try {
for (Element e : table.select(MTGConstants.HTML_TAG_TR)) {
CardShake cs = new CardShake();
cs.setName(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(0).text().trim());
cs.setPrice(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(2).text()));
cs.setPriceDayChange(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(4).text()));
String set = e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(1).text();
set = set.replaceAll("_\\(Foil\\)", "");
cs.setEd(getCodeForExt(set));
list.add(cs);
}
for (Element e : table2.select(MTGConstants.HTML_TAG_TR)) {
CardShake cs = new CardShake();
cs.setName(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(0).text().trim());
cs.setPrice(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(2).text()));
cs.setPriceDayChange(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(4).text()));
String set = e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(1).text();
set = set.replaceAll("_\\(Foil\\)", "");
cs.setEd(getCodeForExt(set));
list.add(cs);
}
} catch (Exception e) {
logger.error("error retrieve cardshake for " + gameFormat, e);
}
return list;
}
use of org.magic.api.beans.CardShake in project MtgDesktopCompanion by nicho92.
the class MTGStockDashBoard method getShakerFor.
@Override
public List<CardShake> getShakerFor(String gameFormat) throws IOException {
connect();
List<CardShake> ret = new ArrayList<>();
for (String filter : new String[] { "normal", "foil" }) for (JsonElement el : interests.get(getString("FORMAT_SHAKER")).getAsJsonObject().get(filter).getAsJsonArray()) {
if (el.getAsJsonObject().get("print").getAsJsonObject().get("legal").getAsJsonObject().get(gameFormat.toLowerCase()) != null && el.getAsJsonObject().get("print").getAsJsonObject().get("legal").getAsJsonObject().get(gameFormat.toLowerCase()).getAsString().equalsIgnoreCase("legal")) {
CardShake cs = new CardShake();
cs.setName(el.getAsJsonObject().get("print").getAsJsonObject().get("name").getAsString());
cs.setPrice(el.getAsJsonObject().get("present_price").getAsDouble());
cs.setPercentDayChange(el.getAsJsonObject().get("percentage").getAsDouble());
cs.setPriceDayChange(el.getAsJsonObject().get("present_price").getAsDouble() - el.getAsJsonObject().get("past_price").getAsDouble());
cs.setDateUpdate(new Date(el.getAsJsonObject().get("date").getAsLong()));
correspondance.forEach((key, value) -> {
if (value == el.getAsJsonObject().get("print").getAsJsonObject().get("set_id").getAsInt()) {
cs.setEd(key);
}
});
ret.add(cs);
}
}
return ret;
}
use of org.magic.api.beans.CardShake in project MtgDesktopCompanion by nicho92.
the class MTGStockDashBoard method getShakeForEdition.
@Override
public List<CardShake> getShakeForEdition(MagicEdition edition) throws IOException {
connect();
List<CardShake> list = new ArrayList<>();
String url = MTGSTOCK_API_URI + "/card_sets/" + correspondance.get(edition.getId());
HttpURLConnection con = getConnection(url);
JsonObject obj = parser.parse(new JsonReader(new InputStreamReader(con.getInputStream()))).getAsJsonObject();
JsonArray arr = obj.get("prints").getAsJsonArray();
for (JsonElement el : arr) {
CardShake cs = new CardShake();
cs.setName(el.getAsJsonObject().get("name").getAsString());
cs.setEd(edition.getId());
cs.setPrice(el.getAsJsonObject().get("latest_price").getAsJsonObject().get("avg").getAsDouble());
list.add(cs);
}
con.disconnect();
return list;
}
use of org.magic.api.beans.CardShake in project MtgDesktopCompanion by nicho92.
the class MTGoldFishDashBoard method getShakeForEdition.
public List<CardShake> getShakeForEdition(MagicEdition edition) throws IOException {
String oldID = edition.getId();
String urlEditionChecker = "";
List<CardShake> list = new ArrayList<>();
if (edition.isOnlineOnly())
urlEditionChecker = getString("URL_EDITIONS") + replace(edition.getId().toUpperCase(), false) + "#online";
else
urlEditionChecker = getString("URL_EDITIONS") + replace(edition.getId().toUpperCase(), false) + "#" + getString("FORMAT");
logger.debug("Parsing dashboard " + urlEditionChecker);
Document doc = read(urlEditionChecker);
Element table = null;
try {
table = doc.select(MTGConstants.HTML_TAG_TABLE).get(1).getElementsByTag(MTGConstants.HTML_TAG_TBODY).get(0);
for (Element e : table.getElementsByTag(MTGConstants.HTML_TAG_TR)) {
CardShake cs = new CardShake();
cs.setName(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(0).text().replaceAll("\\(RL\\)", "").trim());
cs.setImg(new URL("http://" + e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(0).getElementsByTag("a").get(0).attr("data-full-image")));
cs.setPrice(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(3).text()));
cs.setPriceDayChange(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(4).text()));
cs.setPercentDayChange(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(5).text()));
cs.setPriceWeekChange(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(6).text()));
cs.setPercentWeekChange(parseDouble(e.getElementsByTag(MTGConstants.HTML_TAG_TD).get(7).text()));
cs.setEd(oldID);
cs.setDateUpdate(new Date());
list.add(cs);
}
} catch (IndexOutOfBoundsException e) {
logger.error(e);
}
return list;
}
Aggregations