From 44deaf7b0aee195df522838f2e9a59e0a5fe45bb Mon Sep 17 00:00:00 2001 From: marsteralex Date: Mon, 19 Sep 2022 18:10:14 -0700 Subject: [PATCH] WIP: add artist category (#866) * fix https * add beasts * Remove extra file * Prettier-ify code * Prettier-ify * add basic land guesser also added fetcher to filter all cards instead of only unique art * default to original makes basic better * added set symbol to basics added set symbol to the basics game mode. Changed name to "How Basic" * cleanup * changed some pixels * only load set data if needed * hacked fix for removing image from name * removed check from original * remove check from original * sort names by set instead of by set symbol * include battlebond * update cards for categories update for dominaria united * added commander category commander category * update basic land art * can use double feature * removing racist cards upstream this way we don't have to store the cards in the json * remove generated cards from digital commanders * fix counterspell setting default * added difficulty rating * updated padding * add dfc support for commanders * add artists * use latest non-digital if possible * change vsCode settings for python * update with latest non-digital printing * update artist list * update algo to select k samples * cleanup code * equally weight artists * weight everything equally * updated for all artists * update artists * add allowlist * update artists to min 50 art * allow promo to be replaced * update jsons * update with min 100 arts * update code to be smaller jsons * updated to 18 artists per game * update ui * update importing artists * update to 21 * move num artists to top of js file * update artistList to not include artist sigs * update to 50 artists * update for ub * update artist list * update ub defaults * update jsons * allow non-english cards to be replaced * update allowlist * update jsons * add watermark * update jsons * update jsons * make jsons slightly smaller * add checkmarks and x's * remove python * add no answer and checkbox and x Co-authored-by: Austin Chen --- web/public/mtg/app.js | 212 ++++++++++---- web/public/mtg/guess.html | 50 +++- web/public/mtg/importCards.py | 310 ++++++++++++++++---- web/public/mtg/index.html | 69 ++++- web/public/mtg/jsons/artist.json | 2 +- web/public/mtg/jsons/artistList.json | 389 +++++++++++++++++++++++++ web/public/mtg/jsons/basic.json | 2 +- web/public/mtg/jsons/beast.json | 2 +- web/public/mtg/jsons/burn.json | 2 +- web/public/mtg/jsons/commander.json | 2 +- web/public/mtg/jsons/counterspell.json | 2 +- web/public/mtg/jsons/set.json | 2 +- web/public/mtg/jsons/watermark.json | 1 + web/public/mtg/jsons/wm.json | 26 ++ 14 files changed, 931 insertions(+), 140 deletions(-) create mode 100644 web/public/mtg/jsons/artistList.json create mode 100644 web/public/mtg/jsons/watermark.json create mode 100644 web/public/mtg/jsons/wm.json diff --git a/web/public/mtg/app.js b/web/public/mtg/app.js index 2708896a..6a31792f 100644 --- a/web/public/mtg/app.js +++ b/web/public/mtg/app.js @@ -1,11 +1,10 @@ mode = 'PLAY' allData = {} total = 0 -unseenTotal = 0 -probList = [] -nameList = [] +cardNames = [] k = 12 extra = 3 +num_artists = k + extra * 2 artDict = {} totalCorrect = 0 totalSeen = 0 @@ -14,6 +13,7 @@ imagesLeft = k maxRounds = 20 whichGuesser = 'counterspell' un = false +ub = false online = false firstPrint = false flag = true @@ -31,6 +31,8 @@ document.location.search.split('&').forEach((pair) => { online = v[1] } else if (v[0] === 'original') { firstPrint = v[1] + } else if (v[0] === 'ub') { + ub = v[1] } }) @@ -40,22 +42,26 @@ if (whichGuesser === 'basic') { .then((data) => (sets = data)) } +if (whichGuesser === 'watermark') { + fetch('jsons/wm.json') + .then((response) => response.json()) + .then((data) => (sets = data)) +} + let firstFetch = fetch('jsons/' + whichGuesser + '.json') fetchToResponse(firstFetch) function putIntoMapAndFetch(data) { putIntoMap(data.data) - for (const [key, value] of Object.entries(allData)) { - nameList.push(key) - probList.push( - value.length + (probList.length === 0 ? 0 : probList[probList.length - 1]) - ) - unseenTotal = total + if (whichGuesser == 'artist') { + newArtistData = createNewArtistMap() + allData = newArtistData[0] + total = newArtistData[1] } + cardNames = Array.from(Object.keys(allData)) window.console.log(allData) + window.console.log(cardNames) window.console.log(total) - window.console.log(probList) - window.console.log(nameList) if (whichGuesser === 'counterspell') { document.getElementById('guess-type').innerText = 'Counterspell Guesser' } else if (whichGuesser === 'burn') { @@ -66,32 +72,36 @@ function putIntoMapAndFetch(data) { document.getElementById('guess-type').innerText = 'How Basic' } else if (whichGuesser === 'commander') { document.getElementById('guess-type').innerText = 'General Knowledge' + } else if (whichGuesser === 'watermark') { + document.getElementById('guess-type').innerText = 'Watermark It' + } else if (whichGuesser === 'artist') { + document.getElementById('guess-type').innerText = 'Aesthetic Consultation' } + window.console.log(whichGuesser) setUpNewGame() } function getKSamples() { let usedCounters = new Set() - let currentTotal = unseenTotal let samples = {} let i = 0 - while (i < k) { - let rand = Math.floor(Math.random() * currentTotal) - let count = 0 - for (const [key, value] of Object.entries(allData)) { - if (usedCounters.has(key)) { - continue - } else if (count >= rand) { - usedCounters.add(key) - currentTotal -= value.length - unseenTotal-- - let randIndex = Math.floor(Math.random() * value.length) - let arts = allData[key].splice(randIndex, 1) - samples[arts[0].artImg] = [key, arts[0].normalImg] - i++ + let allCards = Array.from(Object.keys(allData)) + shuffleArray(allCards) + window.console.log(allCards) + for (let j = 0; j < allCards.length; j++) { + key = allCards[j] + value = allData[key] + if (usedCounters.has(key)) { + continue + } else { + window.console.log(key) + usedCounters.add(key) + let randIndex = Math.floor(Math.random() * value.length) + let arts = allData[key].splice(randIndex, 1) + samples[arts[0].artImg] = [key, arts[0].normalImg] + i++ + if (i >= k) { break - } else { - count += value.length } } } @@ -101,28 +111,61 @@ function getKSamples() { } } let count = 0 - while (count < extra) { - let rand = Math.floor(Math.random() * total) - for (let j = 0; j < nameList.length; j++) { - if (j >= rand) { - if (usedCounters.has(nameList[j])) { - break - } - usedCounters.add(nameList[j]) - count += 1 + shuffleArray(cardNames) + for (let j = 0; j < cardNames.length; j++) { + key = cardNames[j] + value = cardNames[key] + if (usedCounters.has(key)) { + continue + } else { + window.console.log(key) + usedCounters.add(key) + count++ + if (count >= extra) { break } } } + return [samples, usedCounters] } +function createNewArtistMap() { + let usedCounters = new Set() + let samples = {} + let i = 0 + let newTotal = 0 + let allCards = [] + for (const [key, value] of Object.entries(allData)) { + for (let j = 0; j < value.length; j++) { + allCards.push(key) + } + } + shuffleArray(allCards) + window.console.log(allCards) + for (let j = 0; j < allCards.length; j++) { + key = allCards[j] + value = allData[key] + if (usedCounters.has(key)) { + continue + } else { + window.console.log(key) + usedCounters.add(key) + samples[key] = value + newTotal += value.length + i++ + if (i >= num_artists) { + break + } + } + } + return [samples, newTotal] +} + function fetchToResponse(fetch) { return fetch .then((response) => response.json()) - .then((json) => { - putIntoMapAndFetch(json) - }) + .then((json) => putIntoMapAndFetch(json)) } function determineIfSkip(card) { @@ -131,6 +174,11 @@ function determineIfSkip(card) { return true } } + if (!ub) { + if (card.security_stamp === 'triangle') { + return true + } + } if (!online) { if (card.digital) { return true @@ -138,16 +186,36 @@ function determineIfSkip(card) { } if (firstPrint) { if (whichGuesser == 'basic') { + if (card.set_type !== 'expansion' && card.set_type !== 'funny') { + return true + } + } else if (whichGuesser == 'artist') { if ( - card.set_type !== 'expansion' && - card.set_type !== 'funny' && - card.set_type !== 'draft_innovation' + card.set_type === 'token' || + card.set_type === 'vanguard' || + card.set_type === 'planechase' || + card.set_type === 'archenemy' || + card.set_type === 'memorabilia' + ) { + return true + } + } else if (whichGuesser == 'watermark') { + if ( + card.name === 'Set' || + card.name === 'Planeswalker' || + card.name === 'Flavor' || + card.name === 'Conspiracy' || + card.name === 'Foretell' || + card.name === 'Tarkir' || + card.set === 'h17' || + card.set === 'ptg' || + card.set === 'htr18' ) { return true } } else { if ( - card.reprint === true || + card.reprint || (card.frame_effects && card.frame_effects.includes('showcase')) ) { return true @@ -180,6 +248,9 @@ function putIntoMap(data) { '" /> ' + sets[name][0] } + if (whichGuesser === 'watermark' && sets.hasOwnProperty(name)) { + name = sets[name] + } let normalImg = '' if (card.image_uris.normal) { normalImg = card.image_uris.normal @@ -245,6 +316,7 @@ function setUpNewGame() { currName.innerHTML = namesList[nameIndex - 1] nameBank.appendChild(currName) } + document.querySelectorAll('.temporary-name-holder').forEach((x) => x.remove()) } function removeSymbol(name) { @@ -260,17 +332,53 @@ function checkAnswers() { let incorrect = true if (currCard.dataset.name) { // remove image text - let guess = removeSymbol( - document.getElementById(currCard.dataset.name).innerText - ) - let ans = removeSymbol(artDict[currCard.dataset.url][0]) - window.console.log(ans, guess) + let guessWithSymbol = document.getElementById( + currCard.dataset.name + ).innerHTML + let ansWithSymbol = artDict[currCard.dataset.url][0] + let guess = removeSymbol(guessWithSymbol) + let ans = removeSymbol(ansWithSymbol) incorrect = ans !== guess // decide if their guess was correct + // window.console.log(ans, guess, incorrect) + correctAns = String.fromCodePoint(0x2705) + ' ' + ansWithSymbol + if (incorrect) { + window.console.log( + document.getElementById(currCard.dataset.name), + guess, + ans + ) + document.getElementById(currCard.dataset.name).innerHTML = + String.fromCodePoint(0x274c) + + ' ' + + guessWithSymbol + + '
' + + String.fromCodePoint(0x274c) + + ' ' + + ansWithSymbol + } else { + document.getElementById(currCard.dataset.name).innerHTML = correctAns + } + } else { + answerCorrectionHolder = document.createElement('div') + answerCorrectionHolder.classList.add('name') + answerCorrectionHolder.classList.add('temporary-name-holder') + + answerCorrectionHolder.innerHTML = + String.fromCodePoint(0x274c) + + ' <No Answer> 
' + + String.fromCodePoint(0x274c) + + ' ' + + artDict[currCard.dataset.url][0] + currCard.appendChild(answerCorrectionHolder) } - if (incorrect) currCard.classList.add('incorrect') - // tally some kind of score - if (incorrect) score-- + if (incorrect) { + currCard.classList.add('incorrect') + // tally some kind of score + score-- + // show the correct answer + } + // show the correct card currCard.style.backgroundImage = "url('" + artDict[currCard.dataset.url][1] + "')" diff --git a/web/public/mtg/guess.html b/web/public/mtg/guess.html index feb6805f..3d4147e6 100644 --- a/web/public/mtg/guess.html +++ b/web/public/mtg/guess.html @@ -34,6 +34,13 @@ h1 { font-family: Verdana, Geneva, Tahoma, sans-serif; text-align: center; + display: flex; + flex-direction: row; + } + + .new-game-button { + font-size: 14px; + margin: 0; } form { @@ -52,8 +59,8 @@ } .card { - width: 230px; - height: 208px; + width: 300px; + height: 259px; border: 5px solid lightgrey; margin: 5px; align-items: flex-end; @@ -63,7 +70,7 @@ display: flex; justify-content: center; /*background-size: contain;*/ - background-size: 220px; + background-size: 292px; background-repeat: no-repeat; transition: height 1s, background-image 1s, border 0.4s 0.6s; background-position-y: calc(50% - 18px); @@ -76,8 +83,12 @@ width: 100%; } + .answer-page .card:not([data-name^='name'])::after { + display: none; + } + .answer-page .card { - height: 353px; + height: 453px; /*padding-top: 310px;*/ /*background-size: cover;*/ overflow: hidden; @@ -144,6 +155,7 @@ .card .name { border-radius: 0 0 5px 5px; + width: 300px; } #submit { @@ -165,7 +177,7 @@ padding: 8px 20px; background-color: lightpink; border: none; - position: absolute; + /* position: absolute; */ top: 5px; left: 20px; border-radius: 3px; @@ -201,6 +213,16 @@ h1 { margin-right: 240px; } + + .answer-page .card { + height: 353px; + } + + .card { + width: 230px; + height: 208px; + background-size: 220px; + } } @media screen and (orientation: portrait) and (max-width: 1100px) { @@ -268,7 +290,15 @@ -

:

+

+
+ +
+
+ :   +
+

-
-
- -
-
+
Donate, buy us a boba 🧋
diff --git a/web/public/mtg/importCards.py b/web/public/mtg/importCards.py index 2faab1cd..f552863a 100644 --- a/web/public/mtg/importCards.py +++ b/web/public/mtg/importCards.py @@ -1,10 +1,15 @@ import time import requests import json +import math +# queued categories: 'terror', 'wrath', 'zombie', 'artifact'] # add category name here -allCategories = ['counterspell', 'beast', 'burn', 'commander', 'artist'] #, 'terror', 'wrath', 'zombie', 'artifact'] -specialCategories = ['set', 'basic'] +allCategories = ['counterspell', 'beast', 'burn', 'commander'] +specialCategories = ['set', 'basic', 'watermark'] +artist_denylist = '-a%3A"jason+felix"+-a%3A“Harold+McNeill”+-a%3A"Terese+Nielsen"+-a%3A“Noah+Bradley”' +artist_allowlist = {'David Martin', 'V\u00e9ronique Meignaud', 'Christopher Rush', 'Rebecca Guay', 'DiTerlizzi', + 'Anthony Francisco', 'Wylie Beckert', 'Rovina Cai', 'Dominik Mayer', 'Omar Rayyan', 'Thomas M. Baxa'} def generate_initial_query(category): @@ -17,50 +22,70 @@ def generate_initial_query(category): # string_query += 'otag%3Acreature-removal+o%3A%2Fdestroy+target.%2A+%28creature%7Cpermanent%29%2F+%28t' \ # '%3Ainstant+or+t%3Asorcery%29+o%3Atarget+not%3Aadventure' # elif category == 'wrath': - # string_query += 'otag%3Asweeper-creature+%28t%3Ainstant+or+t%3Asorcery%29+not%3Aadventure' + # string_query += 'otag%3Asweeper-creature+%28t%3Ainstant+or+t%3Asorcery%29+not%3Aadventure+not%3Adfc' elif category == 'burn': string_query += '%28c>%3Dr+or+mana>%3Dr%29+%28o%3A%2Fdamage+to+them%2F+or+%28o%3Adeals+o%3Adamage+o%3A' \ '%2Fcontroller%28%5C.%7C+%29%2F%29+or+o%3A%2F~+deals+%28.%7C..%29+damage+to+%28any+target%7C' \ '.*player%28%5C.%7C+or+planeswalker%29%7C.*opponent%28%5C.%7C+or+planeswalker%29%29%2F%29' \ '+%28type%3Ainstant+or+type%3Asorcery%29+not%3Aadventure+not%3Adfc' elif category == 'commander': - string_query += 'is%3Acommander+%28not%3Adigital+-banned%3Acommander+or+is%3Adigital+legal%3Ahistoricbrawl+or+legal%3Acommander+or+legal%3Abrawl%29' + string_query += 'is%3Acommander+%28not%3Adigital+-banned%3Acommander+or+is%3Adigital+legal%3Ahistoricbrawl' \ + '+or+legal%3Acommander+or+legal%3Abrawl%29' # elif category == 'zombie': - # string_query += '-type%3Alegendary+type%3Azombie+-type%3Atoken' + # string_query += '-type%3Alegendary+type%3Azombie+-type%3Atoken+not%3Adfc' # elif category == 'artifact': - # string_query += 't%3Aartifact&order=released&dir=asc&unique=prints&page=' - # elif category == 'artist': - # string_query+= 'a%3A"Wylie+Beckert"+or+a%3A“Ernanda+Souza”+or+a%3A"randy+gallegos"+or+a%3A“Amy+Weber”+or+a%3A“Dan+Frazier”+or+a%3A“Thomas+M.+Baxa”+or+a%3A“Phil+Foglio”+or+a%3A“DiTerlizzi”+or+a%3A"steve+argyle"+or+a%3A"Veronique+Meignaud"+or+a%3A"Magali+Villeneuve"+or+a%3A"Michael+Sutfin"+or+a%3A“Volkan+Baǵa”+or+a%3A“Franz+Vohwinkel”+or+a%3A"Nils+Hamm"+or+a%3A"Mark+Poole"+or+a%3A"Carl+Critchlow"+or+a%3A"rob+alexander"+or+a%3A"igor+kieryluk"+or+a%3A“Victor+Adame+Minguez”+or+a%3A"johannes+voss"+or+a%3A"Svetlin+Velinov"+or+a%3A"ron+spencer"+or+a%3A"rk+post"+or+a%3A"kev+walker"+or+a%3A"rebecca+guay"+or+a%3A"seb+mckinnon"+or+a%3A"pete+venters"+or+a%3A"greg+staples"+or+a%3A"Christopher+Moeller"+or+a%3A"christopher+rush"+or+a%3A"Mark+Tedin"' + # string_query += 't%3Aartifact+not%3Adatestamped+not%3Adfc&order=released&dir=asc&unique=prints&page=' # add category string query here - string_query += '+-%28set%3Asld+%28%28cn>%3D231+cn<%3D233%29+or+%28cn>%3D321+cn<%3D324%29+or+%28cn>%3D185+cn' \ - '<%3D189%29+or+%28cn>%3D138+cn<%3D142%29+or+%28cn>%3D364+cn<%3D368%29+or+cn%3A669+or+cn%3A670%29' \ - '%29+-name%3A%2F%5EA-%2F+not%3Asplit+-set%3Acmb2+-set%3Acmb1+-set%3Aplist+-st%3Amemorabilia' \ - '+language%3Aenglish&order=released&dir=asc&unique=prints&page=' + string_query += '+-%28set%3Asld+%28cn>%3D231+cn<%3D233+or+cn>%3D436+cn<%3D440+or+cn>%3D321+cn<%3D324+or' \ + '+cn>%3D185+cn<%3D189+or+cn>%3D138+cn<%3D142+or+cn>%3D364+cn<%3D368+or+cn%3A669+or+cn%3A670%29%29+' \ + '-%28set%3Asta+cn>%3D64+cn<%3D126%29+-set%3Acmb2+-set%3Acmb1+not%3Asplit' + string_query += '+-st%3Amemorabilia+-set%3Aplist+-name%3A%2F%5EA-%2F&order=released&dir=asc&unique=prints&page=' print(string_query) return string_query + def generate_initial_special_query(category): string_query = 'https://api.scryfall.com/cards/search?q=' if category == 'set': return 'https://api.scryfall.com/sets' elif category == 'basic': string_query += 't%3Abasic&order=released&dir=asc&unique=prints&page=' + elif category == 'watermark': + string_query += 'has%3Awatermark+not%3Apromo+-t%3Atoken+-st%3Amemorabilia+-set%3Aplist+-name%3A%2F%5EA-%2F&order=released&dir=asc&unique=prints&page=' # add category string query here print(string_query) return string_query +def generate_initial_artist_query(): + string_query = 'https://api.scryfall.com/cards/search?q=' + artist_denylist + \ + '-atag%3Auniverses-beyond+-art%3Aartist-signature+artists%3D1+-st%3Afunny+not%3Aextra+not%3Adigital+-st%3Atoken+-t%3Avanguard+-st%3Amemorabilia+-t%3Ascheme+-t%3Aplane+-t%3APhenomenon&unique=art&as=grid&order=artist&page=' + print("artistList") + print(string_query) + return string_query + + +def generate_individual_artist_query(artists, artist_list): + string_query = 'https://api.scryfall.com/cards/search?q=%28' + for artist in artists: + artist_split = artist_list[artist][0].split() + string_query += 'a%3A“' + '+'.join(artist_split) + '”+or+' + string_query = string_query[:-4] + string_query += '%29+-set%3Aplist-art%3Aartist-signature+artists%3D1+-name%3A%2F%5EA-%2F&order=released&dir=asc&unique=prints&page=' + return string_query + + def fetch_and_write_all(category, query): count = 1 will_repeat = True - all_cards = {'data' : []} - art_names = set() + all_cards = {'data': []} + art_names = dict() while will_repeat: response = fetch(query, count) will_repeat = response['has_more'] - count+=1 - to_compact_write_form(all_cards, art_names, response, category) - + count += 1 + to_compact_write_form(all_cards, art_names, response) + with open('jsons/' + category + '.json', 'w') as f: json.dump(all_cards, f) @@ -68,20 +93,74 @@ def fetch_and_write_all(category, query): def fetch_and_write_all_special(category, query): count = 1 will_repeat = True - all_cards = {'data' : []} - art_names = set() + all_cards = {'data': []} + art_names = dict() while will_repeat: if category == 'set': response = fetch_special(query) else: response = fetch(query, count) will_repeat = response['has_more'] - count+=1 - to_compact_write_form_special(all_cards, art_names, response, category) - + count += 1 + to_compact_write_form_special( + all_cards, art_names, response, category, {}) + with open('jsons/' + category + '.json', 'w') as f: json.dump(all_cards, f) - + + +def fetch_and_write_all_artist(): + all_cards = {'data': []} + will_repeat = True + count = 1 + total_artists = 0 + artists = json.load(open('jsons/artistList.json')) + artist_ids = list(artists.keys()) + print(math.ceil(len(artist_ids)/37.0)) + for i in range(math.ceil(len(artist_ids)/37.0)): + queried_artists_pre = artist_ids[i*37:min((i+1)*37, len(artist_ids))] + queried_artists = [] + for j in range(len(queried_artists_pre)): + if artists[queried_artists_pre[j]][1] >= 50 or artists[queried_artists_pre[j]][0] in artist_allowlist: + queried_artists.append(queried_artists_pre[j]) + print(queried_artists) + print(i) + if len(queried_artists) == 0: + continue + count = 1 + will_repeat = True + art_names = dict() + query = generate_individual_artist_query( + queried_artists, artists) + print(query) + total_artists += len(queried_artists) + print(total_artists) + while will_repeat: + response = fetch(query, count) + will_repeat = response['has_more'] + count += 1 + to_compact_write_form_special( + all_cards, art_names, response, 'artist', artists) + print(len(art_names)) + + with open('jsons/artist.json', 'w') as f: + json.dump(all_cards, f) + + +def fetch_and_write_initial_artist_query(): + prev_artist = "dummy_artist" + artists = {"dummy_artist": [1, 1]} + all_artists_query = generate_initial_artist_query() + will_repeat = True + count = 1 + while will_repeat: + print("artist fetching: "+str(count)) + response = fetch(all_artists_query, count) + will_repeat = response['has_more'] + count += 1 + prev_artist = write_to_artist_list(response, artists, prev_artist) + with open('jsons/artistList.json', 'w') as f: + json.dump(artists, f) def fetch(query, count): @@ -90,31 +169,29 @@ def fetch(query, count): time.sleep(0.1) return response + def fetch_special(query): response = requests.get(f"{query}").json() time.sleep(0.1) return response -def to_compact_write_form(smallJson, art_names, response, category): - fieldsInCard = ['name', 'image_uris', 'flavor_name', 'reprint', 'frame_effects', 'digital', 'set_type'] - data = [] +def write_art(art_names, id, index, card): + if card['digital'] or card['set_type'] == 'promo' or card['promo'] or card['lang'] != 'en': + art_names[id] = index + else: + art_names[id] = -1 + + +def to_compact_write_form(smallJson, art_names, response): + fieldsInCard = ['name', 'image_uris', 'flavor_name', + 'reprint', 'frame_effects', 'digital', 'set_type', 'security_stamp'] + data = smallJson['data'] # write all fields needed in card for card in response['data']: - # do not include racist cards - if 'content_warning' in card and card['content_warning'] == True: + digital_holder = filter_card(card, art_names, data) + if digital_holder == False: continue - # do not repeat art - if 'card_faces' in card: - card_face = card['card_faces'][0] - if 'illustration_id' not in card_face or card_face['illustration_id'] in art_names: - continue - else: - art_names.add(card_face['illustration_id']) - elif 'illustration_id' not in card or card['illustration_id'] in art_names: - continue - else: - art_names.add(card['illustration_id']) write_card = dict() for field in fieldsInCard: # if field == 'name' and category == 'artifact': @@ -123,42 +200,149 @@ def to_compact_write_form(smallJson, art_names, response, category): write_card['name'] = card['card_faces'][0]['name'] elif field == 'image_uris': if 'card_faces' in card and 'image_uris' in card['card_faces'][0]: - write_card['image_uris'] = write_image_uris(card['card_faces'][0]['image_uris']) + write_card['image_uris'] = write_image_uris( + card['card_faces'][0]['image_uris']) else: - write_card['image_uris'] = write_image_uris(card['image_uris']) - elif field in card: + write_card['image_uris'] = write_image_uris( + card['image_uris']) + elif field in card and card[field]: write_card[field] = card[field] - data.append(write_card) - smallJson['data'] += data + if digital_holder != -1: + data[digital_holder] = write_card + else: + data.append(write_card) -def to_compact_write_form_special(smallJson, art_names, response, category): - fieldsInBasic = ['image_uris', 'set', 'set_type', 'digital'] - data = [] + +def to_compact_write_form_special(smallJson, art_names, response, category, artists): + fieldsInBasic = ['image_uris', 'set', + 'set_type', 'digital', 'security_stamp'] + fieldsInArtist = ['image_uris', 'digital', + 'set_type', 'artist_ids', 'security_stamp'] + fieldsInWatermark = ['image_uris', 'watermark', + 'set_type', 'digital', 'security_stamp', 'set'] + data = smallJson['data'] # write all fields needed in card for card in response['data']: - # do not include racist cards - if 'content_warning' in card and card['content_warning'] == True: - continue if category == 'basic': - write_card = dict() # do not repeat art - if 'illustration_id' not in card or card['illustration_id'] in art_names: + digital_holder = filter_card(card, art_names, data) + if digital_holder == False: continue - else: - art_names.add(card['illustration_id']) + write_card = dict() for field in fieldsInBasic: if field == 'image_uris': - write_card['image_uris'] = write_image_uris(card['image_uris']) + write_card['image_uris'] = write_image_uris( + card['image_uris']) elif field == 'set': write_card['name'] = card['set'] - elif field in card: + elif field in card and card[field]: write_card[field] = card[field] - data.append(write_card) + if digital_holder != -1: + data[digital_holder] = write_card + else: + data.append(write_card) + elif category == 'artist': + # do not repeat art + digital_holder = filter_card(card, art_names, data) + if digital_holder == False: + continue + write_card = dict() + for field in fieldsInArtist: + if field == 'artist_ids': + write_card['name'] = artists[card['artist_ids'][0]][0] + elif field == 'image_uris': + if 'card_faces' in card and 'image_uris' in card['card_faces'][0]: + write_card['image_uris'] = write_image_uris( + card['card_faces'][0]['image_uris']) + else: + write_card['image_uris'] = write_image_uris( + card['image_uris']) + elif field in card and card[field]: + write_card[field] = card[field] + if digital_holder != -1: + data[digital_holder] = write_card + else: + data.append(write_card) + elif category == 'watermark': + # do not repeat art + digital_holder = filter_card(card, art_names, data) + if digital_holder == False: + continue + if 'card_faces' in card and 'watermark' in card['card_faces'][0] and 'watermark' in card['card_faces'][1] and card['card_faces'][1]['watermark'] != card['card_faces'][0]['watermark']: + # print(card['name']) + continue + write_card = dict() + for field in fieldsInWatermark: + if field == 'watermark': + # print(card['name']) + if 'card_faces' in card: + write_card['name'] = card['card_faces'][0]['watermark'].capitalize( + ) + else: + write_card['name'] = card['watermark'].capitalize() + elif field == 'image_uris': + if 'card_faces' in card and 'image_uris' in card['card_faces'][0]: + write_card['image_uris'] = write_image_uris( + card['card_faces'][0]['image_uris']) + else: + write_card['image_uris'] = write_image_uris( + card['image_uris']) + elif field in card and card[field]: + write_card[field] = card[field] + if digital_holder != -1: + data[digital_holder] = write_card + else: + data.append(write_card) else: + # print(card['name']) + # print(category) if card['set_type'] != 'token': - smallJson[card['code']] = [card['name'],card['icon_svg_uri']] - - smallJson['data'] += data + smallJson[card['code']] = [card['name'], card['icon_svg_uri']] + + +def filter_card(card, art_names, data): + # do not include racist cards + if 'content_warning' in card and card['content_warning'] == True: + return False + # do not repeat art + digital_holder = -1 + if 'card_faces' in card: + card_face = card['card_faces'][0] + if 'illustration_id' not in card_face or card_face['illustration_id'] in art_names and (art_names[card_face['illustration_id']] < 0 or card['digital']): + return False + else: + ind = len(data) + if (card_face['illustration_id'] in art_names): + digital_holder = art_names[card['illustration_id']] + ind = -1 + write_art( + art_names, card_face['illustration_id'], ind, card) + elif 'illustration_id' not in card or card['illustration_id'] in art_names and (art_names[card['illustration_id']] < 0 or card['digital']): + return False + else: + ind = len(data) + if (card['illustration_id'] in art_names): + digital_holder = art_names[card['illustration_id']] + ind = -1 + write_art(art_names, card['illustration_id'], ind, card) + return digital_holder + + +def write_to_artist_list(response, artists, prev_artist): + for card in response['data']: + artist_id = card['artist_ids'][0] + artist = card['artist'] + if artist_id not in artists: + if artists[prev_artist][1] < 10: + del artists[prev_artist] + prev_artist = artist_id + print(artist) + artists[artist_id] = [artist, 1] + else: + if len(artist) < len(artists[artist_id][0]): + artists[artist_id][0] = artist + artists[artist_id][1] += 1 + return prev_artist # only write images needed @@ -181,4 +365,8 @@ if __name__ == "__main__": fetch_and_write_all(category, generate_initial_query(category)) for category in specialCategories: print(category) - fetch_and_write_all_special(category, generate_initial_special_query(category)) + fetch_and_write_all_special( + category, generate_initial_special_query(category)) + # uncomment this once in a while, but it's expensive to run + fetch_and_write_initial_artist_query() + fetch_and_write_all_artist() diff --git a/web/public/mtg/index.html b/web/public/mtg/index.html index 38aeb9f7..93f1ca7a 100644 --- a/web/public/mtg/index.html +++ b/web/public/mtg/index.html @@ -18,11 +18,13 @@ })(window, document, 'script', 'dataLayer', 'GTM-M3MBVGG') @@ -151,7 +153,7 @@ id="counterspell" name="whichguesser" value="counterspell" - onchange="updateSettingDefault(true, true, false)" + onchange="updateSettingDefault(true, true, true, false, 'only first printing')" checked />