Search in sources :

Example 1 with RetrievableDeck

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;
}
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 2 with RetrievableDeck

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;
}
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 3 with RetrievableDeck

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;
}
Also used : JsonElement(com.google.gson.JsonElement) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) RetrievableDeck(org.magic.api.beans.RetrievableDeck) JsonObject(com.google.gson.JsonObject) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) JsonParser(com.google.gson.JsonParser)

Example 4 with RetrievableDeck

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();
    }
}
Also used : RetrievableDeck(org.magic.api.beans.RetrievableDeck) MagicDeck(org.magic.api.beans.MagicDeck)

Example 5 with RetrievableDeck

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