Skip to content

Commit

Permalink
update archidekt and moxfield deck sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
nicol authored and nicol committed Nov 30, 2024
1 parent 6323956 commit 71d8f57
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,48 +92,54 @@ public MTGDeck getDeck(RetrievableDeck info) throws IOException {
public List<RetrievableDeck> getDeckList(String filter) throws IOException {
List<RetrievableDeck> 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;
Expand All @@ -148,8 +154,7 @@ public String getName() {
public Map<String, MTGProperty> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,39 +80,53 @@ private void load(JsonObject json,String key, Map<MTGCard, Integer> main) {
}

});


}

@Override
public Map<String, MTGProperty> getDefaultAttributes() {
var m = super.getDefaultAttributes();
m.put("MAX_PAGE", MTGProperty.newIntegerProperty("2", "number of page to query", 1, 10));
return m;
}


@Override
public List<RetrievableDeck> getDeckList(String filter) throws IOException {
var json = RequestBuilder.build()

var ret = new ArrayList<RetrievableDeck>();

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<RetrievableDeck>();
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);
}


}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 71d8f57

Please sign in to comment.