use of org.magic.api.beans.MagicPrice in project MtgDesktopCompanion by nicho92.
the class DeckTutorPricer method parseResult.
private List<MagicPrice> parseResult(String response) {
List<MagicPrice> list = new ArrayList<>();
JsonElement e = parser.parse(response);
JsonArray arr = e.getAsJsonObject().get("results").getAsJsonObject().get("items").getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
JsonObject item = arr.get(i).getAsJsonObject();
MagicPrice price = new MagicPrice();
price.setFoil(false);
price.setSeller(item.get("seller").getAsJsonObject().get("nick").getAsString());
price.setSite(getName());
price.setLanguage(item.get("language").getAsString());
price.setQuality(item.get("condition").getAsString());
price.setCurrency("EUR");
price.setValue(Double.parseDouble(item.get("price").getAsString().replaceAll(price.getCurrency(), "").trim()));
price.setUrl("https://mtg.decktutor.com/insertions/" + item.get("code").getAsString() + "/" + item.get("title").getAsString().replaceAll(" - ", "-").replaceAll(" ", "-") + ".html");
price.setShopItem(item);
JsonArray attrs = item.get("attrs").getAsJsonArray();
if (attrs.size() < 0) {
price.setFoil(false);
} else {
price.setFoil(attrs.toString().contains("foil"));
}
// https://mtg.decktutor.com/insertions/EU1BCUS32554473N/lotus-petal-tmp-english-good.html
list.add(price);
}
logger.info(getName() + " found " + list.size() + " items");
return list;
}
use of org.magic.api.beans.MagicPrice in project MtgDesktopCompanion by nicho92.
the class EbayPricer method getPrice.
public List<MagicPrice> getPrice(MagicEdition me, MagicCard card) throws IOException {
List<MagicPrice> prices = new ArrayList<>();
String url = getString("URL");
url = url.replaceAll("%API_KEY%", getString("API_KEY"));
url = url.replaceAll("%COUNTRY%", getString("COUNTRY"));
url = url.replaceAll("%MAX%", getString("MAX"));
keyword = card.getName();
if (me != null)
keyword += " " + me.getSet();
setProperty("KEYWORD", keyword);
keyword = URLEncoder.encode(keyword, getString("ENCODING"));
String link = url.replaceAll("%KEYWORD%", keyword);
logger.info(getName() + " looking for " + keyword);
JsonReader reader = new JsonReader(new InputStreamReader(new URL(link).openStream(), "UTF-8"));
JsonElement root = new JsonParser().parse(reader);
JsonElement articles = root.getAsJsonObject().entrySet().iterator().next().getValue().getAsJsonArray().get(0).getAsJsonObject().get("searchResult");
if (articles.getAsJsonArray().get(0).getAsJsonObject().get("item") == null) {
logger.info(getName() + " find nothing");
return prices;
}
JsonArray items = articles.getAsJsonArray().get(0).getAsJsonObject().get("item").getAsJsonArray();
logger.trace(items);
for (JsonElement el : items) {
MagicPrice mp = new MagicPrice();
String etat = "";
String title = el.getAsJsonObject().get("title").getAsString();
String consultURL = el.getAsJsonObject().get("viewItemURL").getAsString();
double price = el.getAsJsonObject().get("sellingStatus").getAsJsonArray().get(0).getAsJsonObject().get("currentPrice").getAsJsonArray().get(0).getAsJsonObject().get("__value__").getAsDouble();
String currency = el.getAsJsonObject().get("sellingStatus").getAsJsonArray().get(0).getAsJsonObject().get("currentPrice").getAsJsonArray().get(0).getAsJsonObject().get("@currencyId").getAsString();
try {
etat = el.getAsJsonObject().get("condition").getAsJsonArray().get(0).getAsJsonObject().get("conditionDisplayName").getAsString();
} catch (NullPointerException e) {
etat = "";
}
mp.setSeller(title);
mp.setUrl(consultURL);
mp.setCurrency(currency);
mp.setValue(price);
mp.setSite(getName());
mp.setQuality(etat);
prices.add(mp);
}
logger.info(getName() + " find " + prices.size() + " item(s)");
java.util.Collections.sort(prices);
return prices;
}
use of org.magic.api.beans.MagicPrice in project MtgDesktopCompanion by nicho92.
the class MagicCardMarketPricer2 method getPrice.
public List<MagicPrice> getPrice(MagicEdition me, MagicCard card) throws IOException {
try {
if (me == null)
me = card.getEditions().get(0);
lists = new ArrayList<>();
logger.info(getName() + " looking for " + card + " " + me);
if (me.getRarity() != null)
if (!getBoolean("COMMONCHECK") && me.getRarity().equalsIgnoreCase("Common")) {
MagicPrice mp = new MagicPrice();
mp.setCurrency("EUR");
mp.setValue(0.01);
mp.setSite(getName());
mp.setSeller("Not checked common");
lists.add(mp);
return lists;
}
ProductServices pService = new ProductServices();
EnumMap<PRODUCT_ATTS, String> atts = new EnumMap<>(PRODUCT_ATTS.class);
atts.put(PRODUCT_ATTS.idGame, "1");
atts.put(PRODUCT_ATTS.exact, getString("IS_EXACT"));
if (!getString("LANGUAGE_ID").equals(""))
atts.put(PRODUCT_ATTS.idLanguage, getString("LANGUAGE_ID"));
if (getString("USER_ARTICLE").equals("false")) {
Product p = getProductFromCard(card, pService.findProduct(card.getName(), atts));
if (p != null) {
p = pService.getProductById(p.getIdProduct());
MagicPrice mp = new MagicPrice();
mp.setSeller(String.valueOf(p.getExpansionName()));
mp.setValue(p.getPriceGuide().getLOW());
mp.setQuality("");
mp.setUrl("https://www.magiccardmarket.eu" + p.getWebsite());
mp.setSite(getName());
mp.setFoil(false);
mp.setCurrency("EUR");
mp.setLanguage(String.valueOf(p.getLocalization()));
lists.add(mp);
}
} else {
List<Product> list = pService.findProduct(card.getName(), atts);
Product resultat = getProductFromCard(card, list);
if (resultat == null) {
logger.info(getName() + " found no item");
return lists;
}
ArticleService aServ = new ArticleService();
EnumMap<ARTICLES_ATT, String> aatts = new EnumMap<>(ARTICLES_ATT.class);
aatts.put(ARTICLES_ATT.start, "0");
aatts.put(ARTICLES_ATT.maxResults, getString("MAX"));
if (!getString("LANGUAGE_ID").equals(""))
aatts.put(ARTICLES_ATT.idLanguage, getString("LANGUAGE_ID"));
if (!getString("MIN_CONDITION").equals(""))
aatts.put(ARTICLES_ATT.minCondition, getString("MIN_CONDITION"));
List<Article> articles = aServ.find(resultat, aatts);
logger.debug(getName() + " found " + articles.size() + " items");
for (Article a : articles) {
MagicPrice mp = new MagicPrice();
mp.setSeller(String.valueOf(a.getSeller()));
mp.setCountry(String.valueOf(a.getSeller().getAddress().getCountry()));
mp.setValue(a.getPrice());
mp.setQuality(a.getCondition());
mp.setUrl("https://www.magiccardmarket.eu" + resultat.getWebsite());
mp.setSite("MagicCardMarket");
mp.setFoil(a.isFoil());
mp.setCurrency("EUR");
mp.setLanguage(a.getLanguage().toString());
mp.setShopItem(a);
lists.add(mp);
}
}
} catch (Exception e) {
logger.error("Error retrieving prices for " + card, e);
logger.error(e);
}
return lists;
}
use of org.magic.api.beans.MagicPrice in project MtgDesktopCompanion by nicho92.
the class MagicCardMarketPricer2 method alertDetected.
@Override
public void alertDetected(final List<MagicPrice> p) {
ThreadManager.getInstance().execute(() -> {
if (!p.isEmpty() && getString("AUTOMATIC_ADD_CARD_ALERT").equals("true")) {
CartServices cart = new CartServices();
try {
List<Article> list = new ArrayList<>();
for (MagicPrice mp : p) {
Article a = (Article) mp.getShopItem();
a.setCount(1);
list.add(a);
}
boolean res = cart.addArticles(list);
logger.info("add " + list + " to card :" + res);
} catch (Exception e) {
logger.error("Could not add " + p + " to cart", e);
}
}
}, "addCart");
}
use of org.magic.api.beans.MagicPrice in project MtgDesktopCompanion by nicho92.
the class MagicVillePricer method getPrice.
public List<MagicPrice> getPrice(MagicEdition me, MagicCard card) throws IOException {
list.clear();
String html = getString("URL");
if (me == null)
me = card.getEditions().get(0);
String keyword = "";
try {
keyword = getMGVILLCodeEdition(me) + prefixZeros(card.getNumber().replaceAll("a", "").trim(), 3);
} catch (Exception e) {
logger.error("no number for " + card);
return list;
}
setProperty("KEYWORD", keyword);
String url = html + keyword;
logger.info(getName() + " looking for prices " + url);
doc = Jsoup.connect(url).userAgent(getString("USER_AGENT")).timeout(0).get();
Element table = null;
try {
// select the first table.
table = doc.select("table[width=98%]").get(2);
} catch (IndexOutOfBoundsException e) {
logger.info(getName() + " no sellers");
return list;
}
Elements rows = table.select(MTGConstants.HTML_TAG_TR);
for (int i = 3; i < rows.size(); i = i + 2) {
Element ligne = rows.get(i);
Elements cols = ligne.getElementsByTag(MTGConstants.HTML_TAG_TD);
MagicPrice mp = new MagicPrice();
String price = cols.get(4).text();
price = price.substring(0, price.length() - 1);
mp.setValue(Double.parseDouble(price));
mp.setCurrency("EUR");
mp.setSeller(cols.get(0).text());
mp.setSite(getName());
mp.setUrl(url);
mp.setQuality(cols.get(2).text());
mp.setLanguage(cols.get(1).getElementsByTag("span").text());
mp.setCountry("France");
list.add(mp);
}
logger.info(getName() + " found " + list.size() + " item(s) return " + getString("MAX") + " items");
if (list.size() > Integer.parseInt(getString("MAX")) && Integer.parseInt(getString("MAX")) > -1)
return list.subList(0, Integer.parseInt(getString("MAX")));
return list;
}
Aggregations