Search in sources :

Example 6 with RetrievableDeck

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;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) RetrievableDeck(org.magic.api.beans.RetrievableDeck) URISyntaxException(java.net.URISyntaxException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URL(java.net.URL)

Example 7 with RetrievableDeck

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) RetrievableDeck(org.magic.api.beans.RetrievableDeck) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) URISyntaxException(java.net.URISyntaxException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URI(java.net.URI) HttpClient(org.apache.http.client.HttpClient) BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Example 8 with RetrievableDeck

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;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) RetrievableDeck(org.magic.api.beans.RetrievableDeck) URISyntaxException(java.net.URISyntaxException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URI(java.net.URI)

Example 9 with RetrievableDeck

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;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) RetrievableDeck(org.magic.api.beans.RetrievableDeck) URISyntaxException(java.net.URISyntaxException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URI(java.net.URI)

Aggregations

RetrievableDeck (org.magic.api.beans.RetrievableDeck)9 URISyntaxException (java.net.URISyntaxException)8 ArrayList (java.util.ArrayList)8 URI (java.net.URI)7 Document (org.jsoup.nodes.Document)7 Element (org.jsoup.nodes.Element)7 Elements (org.jsoup.select.Elements)7 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 URL (java.net.URL)1 HttpResponse (org.apache.http.HttpResponse)1 NameValuePair (org.apache.http.NameValuePair)1 HttpClient (org.apache.http.client.HttpClient)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPost (org.apache.http.client.methods.HttpPost)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 MagicDeck (org.magic.api.beans.MagicDeck)1