From f157173a36ed1b66d09294fbd1979035540caf98 Mon Sep 17 00:00:00 2001 From: nicol Date: Mon, 25 Nov 2024 18:03:42 +0100 Subject: [PATCH] remove deprecated mtgadecksniffer --- .../decksniffer/impl/MTGADecksSniffer.java | 161 ------------------ src/main/resources/data/default-conf.xml | 4 - 2 files changed, 165 deletions(-) delete mode 100644 src/main/java/org/magic/api/decksniffer/impl/MTGADecksSniffer.java diff --git a/src/main/java/org/magic/api/decksniffer/impl/MTGADecksSniffer.java b/src/main/java/org/magic/api/decksniffer/impl/MTGADecksSniffer.java deleted file mode 100644 index 45f31b168..000000000 --- a/src/main/java/org/magic/api/decksniffer/impl/MTGADecksSniffer.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.magic.api.decksniffer.impl; - -import static org.magic.services.tools.MTG.getEnabledPlugin; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.RegExUtils; -import org.magic.api.beans.MTGDeck; -import org.magic.api.beans.technical.RetrievableDeck; -import org.magic.api.interfaces.MTGCardsProvider; -import org.magic.api.interfaces.abstracts.AbstractDeckSniffer; -import org.magic.services.network.RequestBuilder; -import org.magic.services.network.URLTools; - -public class MTGADecksSniffer extends AbstractDeckSniffer { - - private static final String TRUE = "true"; - private static final String FALSE = "false"; - private static final String URL="https://mtgadecks.net"; - - - @Override - public STATUT getStatut() { - return STATUT.DEPRECATED; - } - - @Override - public String[] listFilter() { - return new String[] {"Control","Aggro","Combo","Midrange","Aggro-Control"}; - } - - @Override - public MTGDeck getDeck(RetrievableDeck info) throws IOException { - var d = info.toBaseDeck(); - - var doc = URLTools.extractAsHtml(info.getUrl().toASCIIString()); - - - var div = doc.select("p#mtga"); - - - for(var s : div.html().split("
")) - { - if(!s.isEmpty()) - { - - try { - AbstractMap.SimpleEntry entry = (parseString(s)); - var mc = getEnabledPlugin(MTGCardsProvider.class).searchCardByName(entry.getKey().substring(0,entry.getKey().indexOf('(')).trim(), null, true).get(0); - d.getMain().put(mc, entry.getValue()); - notify(mc); - } - catch(Exception e) - { - logger.error("error loading {} : {}",s,e); - } - - } - } - return d; - } - - @Override - public List getDeckList(String filter) throws IOException { - - List ret = new ArrayList<>(); - - RequestBuilder e = RequestBuilder.build() - .setClient(URLTools.newClient()) - .get() - .url(URL+"/serverSide") - .addHeader("x-requested-with", "XMLHttpRequest") - .addContent("draw", "2") - .addContent("start", "0") - .addContent("length", "100") - .addContent("search[value]", "") - .addContent("search[regex]", FALSE) - .addContent("draw", "2") - .addContent("columns[0][data]","0") - .addContent("columns[0][name]","deckname") - .addContent("columns[0][searchable]",FALSE) - .addContent("columns[0][orderable]",TRUE) - .addContent("columns[0][orderable]","") - .addContent("columns[0][search][regex]",FALSE) - .addContent("columns[1][data]","1") - .addContent("columns[1][name]","colors") - .addContent("columns[1][searchable]",FALSE) - .addContent("columns[1][orderable]",FALSE) - .addContent("columns[1][search][value]","") - .addContent("columns[1][search][regex]",FALSE) - .addContent("columns[2][data]","2") - .addContent("columns[2][name]","archetype") - .addContent("columns[2][searchable]",FALSE) - .addContent("columns[2][orderable]",FALSE) - .addContent("columns[2][search][value]","") - .addContent("columns[2][search][regex]",FALSE) - .addContent("columns[3][name]","real_update") - .addContent("columns[3][searchable]",FALSE) - .addContent("columns[3][orderable]",TRUE) - .addContent("columns[3][search][value]","") - .addContent("columns[3][search][regex]",FALSE) - .addContent("&order[0][column]","3") - .addContent("&order[0][dir]","desc"); - - if(filter!=null && !filter.isEmpty()) - e.addContent("data", "archetype="+ArrayUtils.indexOf(listFilter(),filter)); - - - var arr = e.toJson().getAsJsonObject().get("data").getAsJsonArray(); - - arr.forEach(a->{ - - var deck = new RetrievableDeck(); - - var name = URLTools.toHtml(a.getAsJsonArray().get(0).getAsString()).select("a").text(); - name = name.substring(0,name.indexOf(" by ")); - name = RegExUtils.replaceAll(name, "BO1","").trim(); - deck.setName(name); - - try { - deck.setUrl(new URI(URL+URLTools.toHtml(a.getAsJsonArray().get(0).getAsString()).select("a").attr("href"))); - } catch (URISyntaxException e1) { - logger.error(e1); - } - - deck.setAuthor(URLTools.toHtml(a.getAsJsonArray().get(0).getAsString()).select("p").text()); - - - var colors = URLTools.toHtml(a.getAsJsonArray().get(1).getAsString()).select("img").attr("alt"); - var deckColor = new StringBuilder(); - - for(var i=0;iorg.magic.api.decksniffer.impl.MTGJSonDeckSniffer true - - org.magic.api.decksniffer.impl.MTGADecksSniffer - true - org.magic.api.decksniffer.impl.ArchidektDeckSniffer true