Search in sources :

Example 16 with MagicPrice

use of org.magic.api.beans.MagicPrice in project MtgDesktopCompanion by nicho92.

the class CardKingdomPricer 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 url = html + format(findGoodEds(me.getSet())) + "/" + format(card.getName());
    Elements prices = null;
    Elements qualities = null;
    logger.info(getName() + " looking for prices " + url);
    try {
        doc = Jsoup.connect(url).userAgent(getString("USER_AGENT")).timeout(0).get();
        qualities = doc.select(".cardTypeList li");
        prices = doc.select(".stylePrice");
    } catch (Exception e) {
        logger.info(getName() + " no item : " + e.getMessage());
        return list;
    }
    List<MagicPrice> lstPrices = new ArrayList<>();
    for (int i = 0; i < qualities.size(); i++) {
        MagicPrice mp = new MagicPrice();
        String price = prices.get(i).html().replaceAll("\\$", "");
        mp.setValue(Double.parseDouble(price));
        mp.setCurrency("$");
        mp.setSeller("Card Kingdom");
        mp.setSite(getName());
        mp.setUrl(url);
        mp.setQuality(qualities.get(i).html());
        mp.setLanguage("English");
        if (!qualities.get(i).hasClass("disabled"))
            lstPrices.add(mp);
    }
    logger.info(getName() + " found " + lstPrices.size() + " item(s)");
    return lstPrices;
}
Also used : MagicPrice(org.magic.api.beans.MagicPrice) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements) IOException(java.io.IOException)

Example 17 with MagicPrice

use of org.magic.api.beans.MagicPrice in project MtgDesktopCompanion by nicho92.

the class DeckTutorPricer method alertDetected.

@Override
public void alertDetected(List<MagicPrice> p) {
    if (getString("AUTOMATIC_ADD_CARD_ALERT").equals("true")) {
        for (MagicPrice mtgprice : p) {
            String code = "";
            String price = "";
            String quantity = "";
            HttpPost reqSearch = new HttpPost(getString("URL") + "/carts/updateInsertion");
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) MagicPrice(org.magic.api.beans.MagicPrice)

Aggregations

MagicPrice (org.magic.api.beans.MagicPrice)17 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 URL (java.net.URL)5 InputStreamReader (java.io.InputStreamReader)4 MTGPricesProvider (org.magic.api.interfaces.MTGPricesProvider)4 JsonElement (com.google.gson.JsonElement)3 JsonReader (com.google.gson.stream.JsonReader)3 Elements (org.jsoup.select.Elements)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 MkmException (org.api.mkm.exceptions.MkmException)2 Article (org.api.mkm.modele.Article)2 Element (org.jsoup.nodes.Element)2 MagicCard (org.magic.api.beans.MagicCard)2 MagicEdition (org.magic.api.beans.MagicEdition)2 JsonObject (com.google.gson.JsonObject)1 Template (freemarker.template.Template)1