use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class MTGSalvationDeckSniffer method getDeckList.
public List<RetrievableDeck> getDeckList() throws IOException {
String url = getString("URL") + "/decks?filter-format=" + getFormatCode(getString("FORMAT")) + "&filter-deck-time-frame=" + getString("FILTER");
List<RetrievableDeck> list = new ArrayList<>();
int nbPage = 1;
int maxPage = Integer.parseInt(getString("MAX_PAGE"));
for (int i = 1; i <= maxPage; i++) {
String link = url + "&page=" + nbPage;
logger.debug("sniff url : " + link);
Document d = Jsoup.connect(link).userAgent(getString("USER_AGENT")).get();
Elements e = null;
e = d.select("tr.deck-row");
for (Element cont : e) {
RetrievableDeck deck = new RetrievableDeck();
deck.setName(cont.select("a.deck-name").html());
deck.setAuthor(cont.select("small.deck-credit a").text());
try {
deck.setUrl(new URL(getString("URL") + "/" + cont.select("a.deck-name").attr("href")).toURI());
} catch (URISyntaxException e1) {
deck.setUrl(null);
}
deck.setDescription(cont.select("span.deck-type").html());
deck.setColor(parseColor(cont.select("script").html()));
list.add(deck);
}
nbPage++;
}
return list;
}
use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class MTGTop8DeckSniffer method getDeckList.
@Override
public List<RetrievableDeck> getDeckList() throws IOException {
HttpClient httpClient = HttpClientBuilder.create().build();
StringBuilder res = new StringBuilder();
for (int i = 0; i < Integer.parseInt(getString("MAX_PAGE")); i++) {
HttpPost reqSearch = new HttpPost(getString("URL") + "/search");
List<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("current_page", String.valueOf(i + 1)));
nvps.add(new BasicNameValuePair("event_titre", getString("EVENT_FILTER")));
nvps.add(new BasicNameValuePair("deck_titre", ""));
nvps.add(new BasicNameValuePair("player", ""));
nvps.add(new BasicNameValuePair("format", formats.get(getString("FORMAT"))));
nvps.add(new BasicNameValuePair("MD_check", "1"));
nvps.add(new BasicNameValuePair("cards", getString("CARD_FILTER")));
nvps.add(new BasicNameValuePair("date_start", getString("DATE_START_FILTER")));
nvps.add(new BasicNameValuePair("date_end", ""));
if (getString("COMPETITION_FILTER") != null) {
String[] comp = getString("COMPETITION_FILTER").split(",");
for (String c : comp) nvps.add(new BasicNameValuePair(" compet_check[" + c.toUpperCase() + "]", "1"));
}
reqSearch.setEntity(new UrlEncodedFormEntity(nvps));
logger.debug("snif decks : " + reqSearch.toString());
HttpResponse rep = httpClient.execute(reqSearch);
res.append(EntityUtils.toString(rep.getEntity()));
}
Document d = Jsoup.parse(res.toString());
Elements els = d.select("tr.hover_tr");
List<RetrievableDeck> ret = new ArrayList<>();
for (int i = 0; i < els.size(); i++) {
Element e = els.get(i);
RetrievableDeck dk = new RetrievableDeck();
dk.setName(e.select("td.s11 a").text());
try {
dk.setUrl(new URI(getString("URL") + e.select("td.s11 a").attr("href")));
} catch (URISyntaxException e1) {
dk.setUrl(null);
}
dk.setAuthor(e.select("td.g11 a").text());
dk.setDescription(e.select("td.S10 a").text());
ret.add(dk);
}
return ret;
}
use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class MTGoldFishDeck method getDeckList.
public List<RetrievableDeck> getDeckList() throws IOException {
String url = "";
metagames = getString("METAGAME").equals("true");
List<RetrievableDeck> list = new ArrayList<>();
int nbPage = 1;
int maxPage = Integer.parseInt(getString("MAX_PAGE"));
if (metagames)
maxPage = 1;
for (int i = 1; i <= maxPage; i++) {
if (!metagames)
url = getString("URL") + "/deck/custom/" + getString("FORMAT") + "?page=" + nbPage + "#" + getString("SUPPORT");
else
url = getString("URL") + "metagame/" + getString("FORMAT") + "/full#" + getString("SUPPORT");
logger.debug("sniff url : " + url);
Document d = Jsoup.connect(url).userAgent(getString("USER_AGENT")).get();
Elements e = null;
if (!metagames)
e = d.select("div.deck-tile");
else
e = d.select("div.archetype-tile");
for (Element cont : e) {
Elements desc = cont.select("span.deck-price-" + getString("SUPPORT") + "> a");
Elements colors = cont.select("span.manacost > img");
StringBuilder deckColor = new StringBuilder();
for (Element c : colors) deckColor.append("{").append(c.attr("alt").toUpperCase()).append("}");
RetrievableDeck deck = new RetrievableDeck();
deck.setName(desc.get(0).text());
try {
deck.setUrl(new URI(getString("URL") + desc.get(0).attr("href")));
} catch (URISyntaxException e1) {
deck.setUrl(null);
}
if (metagames)
deck.setAuthor("MtgGoldFish");
else
deck.setAuthor(cont.select("div.deck-author").text());
deck.setColor(deckColor.toString());
for (Element mc : cont.getElementsByTag("li")) {
deck.getKeycards().add(mc.text());
}
list.add(deck);
}
nbPage++;
}
return list;
}
use of org.magic.api.beans.RetrievableDeck in project MtgDesktopCompanion by nicho92.
the class MagicCorporationDecks method getDeckList.
@Override
public List<RetrievableDeck> getDeckList() throws IOException {
Document d = Jsoup.connect(getString("URL") + "/mc.php?rub=decks&limit=0").userAgent(getString("USER_AGENT")).get();
Elements e = d.select("table.html_table > tbody");
List<RetrievableDeck> list = new ArrayList<>();
for (Element cont : e.get(0).getElementsByTag(MTGConstants.HTML_TAG_TR)) {
String name = cont.getElementsByTag(MTGConstants.HTML_TAG_TD).get(1).text();
String url = cont.getElementsByTag(MTGConstants.HTML_TAG_TD).get(1).getElementsByTag("a").attr("href");
String auteur = cont.getElementsByTag(MTGConstants.HTML_TAG_TD).get(5).text();
StringBuilder temp = new StringBuilder();
for (Element color : cont.getElementsByTag(MTGConstants.HTML_TAG_TD).get(2).select("img")) {
if (color.attr("src").contains("white"))
temp.append("{W}");
if (color.attr("src").contains("blue"))
temp.append("{U}");
if (color.attr("src").contains("black"))
temp.append("{B}");
if (color.attr("src").contains("red"))
temp.append("{R}");
if (color.attr("src").contains("green"))
temp.append("{G}");
}
RetrievableDeck deck = new RetrievableDeck();
deck.setName(name);
try {
deck.setUrl(new URI(url));
} catch (URISyntaxException e1) {
deck.setUrl(null);
}
deck.setAuthor(auteur);
deck.setColor(temp.toString());
list.add(deck);
}
return list;
}
Aggregations