From 71d8f579ffc0e025d6863c78a914cdf8ad344698 Mon Sep 17 00:00:00 2001 From: nicol Date: Sun, 1 Dec 2024 00:20:23 +0100 Subject: [PATCH] update archidekt and moxfield deck sniffer --- .../impl/ArchidektDeckSniffer.java | 75 ++++++++++--------- .../decksniffer/impl/MoxfieldDeckSniffer.java | 57 ++++++++------ .../abstracts/AbstractMTGPlugin.java | 2 +- 3 files changed, 77 insertions(+), 57 deletions(-) diff --git a/src/main/java/org/magic/api/decksniffer/impl/ArchidektDeckSniffer.java b/src/main/java/org/magic/api/decksniffer/impl/ArchidektDeckSniffer.java index 86bf3bf68..f2a3b0fcd 100644 --- a/src/main/java/org/magic/api/decksniffer/impl/ArchidektDeckSniffer.java +++ b/src/main/java/org/magic/api/decksniffer/impl/ArchidektDeckSniffer.java @@ -92,48 +92,54 @@ public MTGDeck getDeck(RetrievableDeck info) throws IOException { public List getDeckList(String filter) throws IOException { List ret = new ArrayList<>(); + + for(var i = 1; i<=getInt("MAX_PAGE");i++) + { - var arr = RequestBuilder.build() - .setClient(URLTools.newClient()) - .url(BASE_URI+"/decks/cards/") - .get() - .addContent("orderBy", "-createdAt") - .addContent("formats", String.valueOf(ArrayUtils.indexOf(listFilter(), filter)+1)) - .addContent("pageSize", getString("PAGE_SIZE")) - .addContent("page","1") - .addHeader("accept", URLTools.HEADER_JSON) - .toJson().getAsJsonObject().get("results").getAsJsonArray(); + + var arr = RequestBuilder.build() + .setClient(URLTools.newClient()) + .url(BASE_URI+"/decks/cards/") + .get() + .addContent("orderBy", "-createdAt") + .addContent("formats", String.valueOf(ArrayUtils.indexOf(listFilter(), filter)+1)) + .addContent("pageSize", "50") + .addContent("page",String.valueOf(i)) + .addHeader("accept", URLTools.HEADER_JSON) + .toJson().getAsJsonObject().get("results").getAsJsonArray(); - for(JsonElement el : arr) - { - try { - var d = new RetrievableDeck(); - d.setAuthor(el.getAsJsonObject().get("owner").getAsJsonObject().get("username").getAsString()); - d.setName(el.getAsJsonObject().get("name").getAsString()); - - var build = new StringBuilder(); - build.append(BASE_URI).append("/decks/").append(el.getAsJsonObject().get("id").getAsInt()).append("/"); + for(JsonElement el : arr) + { + try { + var d = new RetrievableDeck(); + d.setAuthor(el.getAsJsonObject().get("owner").getAsJsonObject().get("username").getAsString()); + d.setName(el.getAsJsonObject().get("name").getAsString()); + + var build = new StringBuilder(); + build.append(BASE_URI).append("/decks/").append(el.getAsJsonObject().get("id").getAsInt()).append("/"); - d.setUrl(new URI(build.toString())); - var tmp = new StringBuilder(""); + d.setUrl(new URI(build.toString())); + var tmp = new StringBuilder(""); - for(var s : el.getAsJsonObject().get("colors").getAsJsonObject().entrySet()) - { - if(s.getValue().getAsInt()>0) - tmp.append("{").append(s.getKey()).append("}"); - } + for(var s : el.getAsJsonObject().get("colors").getAsJsonObject().entrySet()) + { + if(s.getValue().getAsInt()>0) + tmp.append("{").append(s.getKey()).append("}"); + } - d.setColor(tmp.toString()); + d.setColor(tmp.toString()); - ret.add(d); + ret.add(d); - } - catch(Exception ex) - { - logger.error("error parsing {}",el, ex); - } + } + catch(Exception ex) + { + logger.error("error parsing {}",el, ex); + } + } + } return ret; @@ -148,8 +154,7 @@ public String getName() { public Map getDefaultAttributes() { var m = super.getDefaultAttributes(); - - m.put("PAGE_SIZE", MTGProperty.newIntegerProperty("50", "number of items per page to query", 50, 100)); + m.put("MAX_PAGE", MTGProperty.newIntegerProperty("2", "number of page to query", 1, 10)); return m; } diff --git a/src/main/java/org/magic/api/decksniffer/impl/MoxfieldDeckSniffer.java b/src/main/java/org/magic/api/decksniffer/impl/MoxfieldDeckSniffer.java index 39175da17..de1b97a62 100644 --- a/src/main/java/org/magic/api/decksniffer/impl/MoxfieldDeckSniffer.java +++ b/src/main/java/org/magic/api/decksniffer/impl/MoxfieldDeckSniffer.java @@ -9,6 +9,7 @@ import org.magic.api.beans.MTGCard; import org.magic.api.beans.MTGDeck; +import org.magic.api.beans.technical.MTGProperty; import org.magic.api.beans.technical.RetrievableDeck; import org.magic.api.interfaces.MTGCardsProvider; import org.magic.api.interfaces.abstracts.AbstractDeckSniffer; @@ -79,39 +80,53 @@ private void load(JsonObject json,String key, Map main) { } }); - - } + + @Override + public Map getDefaultAttributes() { + var m = super.getDefaultAttributes(); + m.put("MAX_PAGE", MTGProperty.newIntegerProperty("2", "number of page to query", 1, 10)); + return m; + } + @Override public List getDeckList(String filter) throws IOException { - var json = RequestBuilder.build() + + var ret = new ArrayList(); + + for(var i = 1; i<=getInt("MAX_PAGE");i++) + { + var json = RequestBuilder.build() .setClient(client) .get() - .url(BASE_URI+"/decks/search?pageNumber=1&pageSize=128&sortType=updated&sortDirection=Descending&fmt="+filter+"&filter=") + .url(BASE_URI+"/decks/search?pageNumber="+i+"&pageSize=128&sortType=updated&sortDirection=Descending&fmt="+filter+"&filter=") .toJson(); - var ret = new ArrayList(); - for(var je : json.getAsJsonObject().get("data").getAsJsonArray()) - { - var jo = je.getAsJsonObject(); - - var dekElement = new RetrievableDeck(); - dekElement.setName(jo.get("name").getAsString()); - dekElement.setAuthor(jo.get("authors").getAsJsonArray().get(0).getAsJsonObject().get("userName").getAsString()); - dekElement.setUrl(URI.create(BASE_URI+"/decks/all/"+jo.get("publicId").getAsString())); - dekElement.setDescription(UITools.formatDateTime(UITools.parseGMTDate(jo.get("createdAtUtc").getAsString()))); - - var c = new StringBuilder(); - jo.get("colors").getAsJsonArray().asList().stream().map(j->j.getAsString()).forEach(s->c.append("{").append(s).append("}")); - - dekElement.setColor(c.toString()); + + for(var je : json.getAsJsonObject().get("data").getAsJsonArray()) + { + var jo = je.getAsJsonObject(); + + var dekElement = new RetrievableDeck(); + dekElement.setName(jo.get("name").getAsString()); + dekElement.setAuthor(jo.get("authors").getAsJsonArray().get(0).getAsJsonObject().get("userName").getAsString()); + dekElement.setUrl(URI.create(BASE_URI+"/decks/all/"+jo.get("publicId").getAsString())); + dekElement.setDescription(UITools.formatDateTime(UITools.parseGMTDate(jo.get("createdAtUtc").getAsString()))); - ret.add(dekElement); - } + var c = new StringBuilder(); + jo.get("colors").getAsJsonArray().asList().stream().map(j->j.getAsString()).forEach(s->c.append("{").append(s).append("}")); + + dekElement.setColor(c.toString()); + + ret.add(dekElement); + } + } + + diff --git a/src/main/java/org/magic/api/interfaces/abstracts/AbstractMTGPlugin.java b/src/main/java/org/magic/api/interfaces/abstracts/AbstractMTGPlugin.java index 25c34225a..e66c43fb3 100644 --- a/src/main/java/org/magic/api/interfaces/abstracts/AbstractMTGPlugin.java +++ b/src/main/java/org/magic/api/interfaces/abstracts/AbstractMTGPlugin.java @@ -206,7 +206,7 @@ public String getString(String k) { if (props.getProperty(k) == null) { logger.error("{} is not found in {}",k,getName()); - props.put(k, getDefaultAttributes().get(k)); + props.put(k, getDefaultAttributes().get(k).getDefaultValue()); save(); load(); }