Search in sources :

Example 6 with MagicDeck

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

the class MTGTop8DeckSniffer method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    Document root = Jsoup.connect(info.getUrl().toString()).userAgent(getString("USER_AGENT")).timeout(0).get();
    MagicDeck d = new MagicDeck();
    d.setDescription(info.getUrl().toString());
    d.setName(info.getName());
    d.setDateCreation(new Date());
    Elements doc = root.select("table.Stable").get(1).select("td table").select(MTGConstants.HTML_TAG_TD);
    boolean side = false;
    for (Element e : doc.select("td table td")) {
        if (e.hasClass("O13")) {
            if (e.text().equalsIgnoreCase("SIDEBOARD"))
                side = true;
        } else {
            int qte = Integer.parseInt(e.text().substring(0, e.text().indexOf(' ')));
            String name = e.select("span.L14").text();
            if (!name.equals("")) {
                MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, null, true).get(0);
                if (!side)
                    d.getMap().put(mc, qte);
                else
                    d.getMapSideBoard().put(mc, qte);
            }
        }
    }
    return d;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Example 7 with MagicDeck

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

the class MagicCorporationDecks method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    Document d = Jsoup.connect(getString("URL") + "/" + info.getUrl().toString()).userAgent(getString("USER_AGENT")).get();
    MagicDeck deck = new MagicDeck();
    deck.setName(info.getName());
    deck.setDescription(d.select("div.block_content").get(4).text().trim());
    deck.setDateCreation(new Date());
    Elements list = d.select("div.liste_deck>ul");
    for (Element ul : list) {
        for (Element li : ul.select("li")) {
            Integer qte = Integer.parseInt(li.text().substring(0, li.text().indexOf(' ')));
            String name = li.getElementsByTag("a").attr("title");
            logger.debug(qte + " " + name);
        }
    }
    return deck;
}
Also used : Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Example 8 with MagicDeck

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

the class TCGPlayerDeckSniffer method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    logger.debug("get deck at " + info.getUrl());
    MagicDeck deck = new MagicDeck();
    deck.setName(info.getName());
    deck.setDescription(info.getUrl().toString());
    deck.setDateCreation(new Date());
    Document d = Jsoup.connect(info.getUrl().toString()).userAgent(getString("USER_AGENT")).get();
    for (Element e : d.select("span.singleTag")) {
        deck.getTags().add(e.text());
    }
    Elements main = d.getElementsByClass("subdeck");
    int taille = main.get(0).getElementsByClass("subdeck-group__card-qty").size();
    for (int i = 0; i < taille; i++) {
        int qte = Integer.parseInt(main.get(0).getElementsByClass("subdeck-group__card-qty").get(i).text());
        String cardName = main.get(0).getElementsByClass("subdeck-group__card-name").get(i).text();
        MagicEdition ed = null;
        if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
            ed = new MagicEdition();
            ed.setId(MTGControler.getInstance().get("default-land-deck"));
        }
        if (cardName.contains("//"))
            cardName = cardName.substring(0, cardName.indexOf("//")).trim();
        MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
        deck.getMap().put(mc, qte);
    }
    if (main.size() > 1) {
        int tailleSide = main.get(1).getElementsByClass("subdeck-group__card-qty").size();
        for (int i = 0; i < tailleSide; i++) {
            int qte = Integer.parseInt(main.get(1).getElementsByClass("subdeck-group__card-qty").get(i).text());
            String cardName = main.get(1).getElementsByClass("subdeck-group__card-name").get(i).text();
            MagicEdition ed = null;
            if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
                ed = new MagicEdition();
                ed.setId(MTGControler.getInstance().get("default-land-deck"));
            }
            if (cardName.contains("//"))
                cardName = cardName.substring(0, cardName.indexOf("//")).trim();
            MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
            deck.getMapSideBoard().put(mc, qte);
        }
    }
    return deck;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Element(org.jsoup.nodes.Element) MagicEdition(org.magic.api.beans.MagicEdition) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Example 9 with MagicDeck

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

the class Apprentice2DeckExport method importDeck.

@Override
public MagicDeck importDeck(File f) throws IOException {
    try (BufferedReader read = new BufferedReader(new FileReader(f))) {
        MagicDeck deck = new MagicDeck();
        deck.setName(f.getName().substring(0, f.getName().indexOf('.')));
        String line = read.readLine();
        int ecart = 0;
        while (line != null) {
            line = line.trim();
            if (!line.startsWith("//")) {
                String[] elements = line.split(getString("SEPARATOR"));
                MagicEdition ed = null;
                try {
                    ed = new MagicEdition();
                    ed.setId(elements[3]);
                } catch (Exception e) {
                    ed = null;
                    ecart = 1;
                }
                String name = elements[2 - ecart].replaceAll("\"", "");
                MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, ed, true).get(0);
                Integer qte = Integer.parseInt(elements[1 - ecart]);
                if (line.startsWith("SB"))
                    deck.getMapSideBoard().put(mc, qte);
                else
                    deck.getMap().put(mc, qte);
            }
            line = read.readLine();
        }
        return deck;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) BufferedReader(java.io.BufferedReader) MagicEdition(org.magic.api.beans.MagicEdition) FileReader(java.io.FileReader) IOException(java.io.IOException) MagicDeck(org.magic.api.beans.MagicDeck)

Example 10 with MagicDeck

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

the class Apprentice2DeckExport method exportStock.

@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
    MagicDeck d = new MagicDeck();
    d.setName(f.getName());
    for (MagicCardStock mcs : stock) {
        d.getMap().put(mcs.getMagicCard(), mcs.getQte());
    }
    export(d, f);
}
Also used : MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Aggregations

MagicDeck (org.magic.api.beans.MagicDeck)40 MagicCard (org.magic.api.beans.MagicCard)21 MagicCardStock (org.magic.api.beans.MagicCardStock)14 Date (java.util.Date)12 MagicEdition (org.magic.api.beans.MagicEdition)10 FileReader (java.io.FileReader)9 IOException (java.io.IOException)8 Document (org.jsoup.nodes.Document)7 Element (org.jsoup.nodes.Element)7 BufferedReader (java.io.BufferedReader)6 ArrayList (java.util.ArrayList)6 Elements (org.jsoup.select.Elements)6 BorderLayout (java.awt.BorderLayout)3 File (java.io.File)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 Dimension (java.awt.Dimension)2 SQLException (java.sql.SQLException)2 JButton (javax.swing.JButton)2 JFileChooser (javax.swing.JFileChooser)2