use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class LotusNoirDecks method getDeckList.
@Override
public List<RetrievableDeck> getDeckList() throws IOException {
String decksUrl = getString("URL") + "?dpage=" + getString("MAX_PAGE") + "&action=" + getString("FORMAT");
logger.debug("snif decks : " + decksUrl);
int nbPage = Integer.parseInt(getString("MAX_PAGE"));
List<RetrievableDeck> list = new ArrayList<>();
for (int i = 1; i <= nbPage; i++) {
Document d = Jsoup.connect(getString("URL") + "?dpage=" + i + "&action=" + getString("FORMAT")).userAgent(getString("USER_AGENT")).timeout(Integer.parseInt(getString("TIMEOUT"))).get();
Elements e = d.select("div.thumb_page");
for (Element cont : e) {
RetrievableDeck deck = new RetrievableDeck();
Element info = cont.select("a").get(0);
String name = info.attr("title").replaceAll("Lien vers ", "").trim();
String url = info.attr("href");
String auteur = cont.select("small").select("a").text();
deck.setName(name);
try {
deck.setUrl(new URI(url));
} catch (URISyntaxException e1) {
deck.setUrl(null);
}
deck.setAuthor(auteur);
deck.setColor("");
list.add(deck);
}
}
return list;
}
use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class TCGPlayerDeckSniffer method getDeckList.
@Override
public List<RetrievableDeck> getDeckList() throws IOException {
String url = getString("URL") + "/magic/deck/search?format=" + getString("FORMAT") + "&page=1";
logger.debug("get List deck at " + url);
List<RetrievableDeck> list = new ArrayList<>();
int nbPage = 1;
int maxPage = Integer.parseInt(getString("MAX_PAGE"));
for (int i = 1; i <= maxPage; i++) {
url = getString("URL") + "/magic/deck/search?format=" + getString("FORMAT") + "&page=" + nbPage;
Document d = Jsoup.connect(url).userAgent(getString("USER_AGENT")).get();
Elements table = d.getElementsByClass("dataTable");
table.get(0).getElementsByTag(MTGConstants.HTML_TAG_TR).remove(0);
for (Element tr : table.get(0).getElementsByClass("gradeA")) {
RetrievableDeck deck = new RetrievableDeck();
String mana = "";
Element manaEl = tr.getElementsByTag(MTGConstants.HTML_TAG_TD).get(0);
if (manaEl.toString().contains("white-mana"))
mana += "{W}";
if (manaEl.toString().contains("blue-mana"))
mana += "{U}";
if (manaEl.toString().contains("black-mana"))
mana += "{B}";
if (manaEl.toString().contains("red-mana"))
mana += "{R}";
if (manaEl.toString().contains("green-mana"))
mana += "{G}";
String deckName = tr.getElementsByTag(MTGConstants.HTML_TAG_TD).get(1).text();
String link = getString("URL") + tr.getElementsByTag(MTGConstants.HTML_TAG_TD).get(1).getElementsByTag("a").attr("href");
String deckPlayer = tr.getElementsByTag(MTGConstants.HTML_TAG_TD).get(2).text();
deck.setColor(mana);
deck.setAuthor(deckPlayer);
deck.setName(deckName);
try {
deck.setUrl(new URI(link));
} catch (URISyntaxException e) {
deck.setUrl(null);
}
list.add(deck);
}
nbPage++;
}
return list;
}
use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class TappedOutDeckSniffer method getDeckList.
public List<RetrievableDeck> getDeckList() throws IOException {
String tappedJson = StringUtils.replaceAll(getString("URL_JSON"), "%FORMAT%", getString("FORMAT"));
logger.debug("sniff url : " + tappedJson);
String responseBody = EntityUtils.toString(httpclient.execute(new HttpGet(tappedJson), httpContext).getEntity());
JsonElement root = new JsonParser().parse(responseBody);
List<RetrievableDeck> list = new ArrayList<>();
for (int i = 0; i < root.getAsJsonArray().size(); i++) {
JsonObject obj = root.getAsJsonArray().get(i).getAsJsonObject();
RetrievableDeck deck = new RetrievableDeck();
deck.setName(obj.get("name").getAsString());
try {
deck.setUrl(new URI(obj.get("resource_uri").getAsString()));
} catch (URISyntaxException e) {
deck.setUrl(null);
}
deck.setAuthor(obj.get("user").getAsString());
deck.setColor("");
list.add(deck);
}
return list;
}
use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class DeckSnifferProviderTests method test.
public void test(MTGDeckSniffer p) {
System.out.println("*****************************" + p.getName());
System.out.println("STAT " + p.getStatut());
System.out.println("PROP " + p.getProperties());
System.out.println("TYPE " + p.getType());
System.out.println("ENAB " + p.isEnable());
System.out.println("FILT " + p.listFilter());
System.out.println("VERS " + p.getVersion());
try {
List<RetrievableDeck> decks = p.getDeckList();
System.out.println("Retrieve decklist OK");
RetrievableDeck d = decks.get(0);
MagicDeck deck = p.getDeck(d);
System.out.println("Retrieve " + deck.getName() + " ok");
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class DeckstatsDeckSniffer method getDeckList.
@Override
public List<RetrievableDeck> getDeckList() throws IOException {
int nbPage = Integer.parseInt(getString("MAX_PAGE"));
List<RetrievableDeck> list = new ArrayList<>();
for (int i = 1; i <= nbPage; i++) {
Document d = Jsoup.connect(getString("URL") + "/" + getString("FORMAT") + "/?lng=fr&page=" + i).userAgent(getString("USER_AGENT")).timeout(Integer.parseInt(getString("TIMEOUT"))).get();
Elements e = d.select("tr.touch_row");
for (Element cont : e) {
RetrievableDeck deck = new RetrievableDeck();
Element info = cont.select("a").get(0);
String idColor = cont.select("img").get(0).attr("src");
idColor = idColor.substring(idColor.lastIndexOf('/') + 1, idColor.lastIndexOf('.'));
String name = info.text();
String url = info.attr("href");
String auteur = cont.select("a").get(1).text();
deck.setName(name);
try {
deck.setUrl(new URI(url));
} catch (URISyntaxException e1) {
deck.setUrl(null);
}
deck.setAuthor(auteur);
deck.setColor(cacheColor.get(Integer.parseInt(idColor)));
list.add(deck);
}
}
return list;
}
Aggregations