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;
}
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;
}
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;
}
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;
}
}
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);
}
Aggregations