From 6edfaf71721e644e0ee684614a7ed65c7a822e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Mon, 4 Nov 2024 20:16:57 +0000 Subject: [PATCH] Show mastered decks on front page --- README.org | 1 + indexgen.py | 18 ++++++++++++++++++ tcgcore.py | 38 ++++++++++++++++++++++++++++++++++++-- tradegen.py | 11 ++++++----- variables-template.py | 1 + 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/README.org b/README.org index d6a22c9..68ded3b 100644 --- a/README.org +++ b/README.org @@ -28,6 +28,7 @@ Python scripts to generate a mobile-friendly static site for tracking tcg cards - =collectthreshold=: minimum number of owned cards for putting a deck in the “collecting” category - =keepsig=: True if you always want to keep one copy of your signature, False if you want to make them all available for trading - =tradestatement=: statement to place on your trading page + - =maxmastered=: maximum number of most recently mastered decks to show on the index page - Run the following: #+BEGIN_SRC bash python3 setup.py diff --git a/indexgen.py b/indexgen.py index 31576c6..abcd4b3 100644 --- a/indexgen.py +++ b/indexgen.py @@ -226,6 +226,24 @@ def indexgen(): if sketch > 19: content.write("" + str(int(sketch / 20)) + " completed\n") content.write("\n\n") + decksofinterest = [] + for card in tcgcore.ownedcards(): + if card[0:4] != "sig_": + decksofinterest.append(card[:-2]) + decksofinterest = sorted(list(dict.fromkeys(decksofinterest))) + mastereddecks = [] + for deck in decksofinterest: + if tcgcore.deckmastered(deck): + mastereddecks.append({"name":deck,"date":tcgcore.datemastered(deck)}) + mastereddecks = sorted(mastereddecks,key=lambda d: d["date"],reverse=True) + if len(mastereddecks) > 0: + content.write("

mastered decks

\n

") + masteredcount = 1 + for deck in mastereddecks: + if masteredcount < variables.maxmastered: + content.write("") + masteredcount += 1 + content.write("

\n") sigs = [] for card in tcgcore.ownedcards(): if card[0:4] == "sig_": diff --git a/tcgcore.py b/tcgcore.py index 353e3f6..9df36a0 100644 --- a/tcgcore.py +++ b/tcgcore.py @@ -31,6 +31,36 @@ def deckmastered(deck): else: return False +def datemastered(deck): + if deckmastered(deck): + deckdates = [] + for event in log.log: + try: + if event["received"]: + for card in event["received"]: + if card[:-2] == deck: + deckdates.append({"card":card,"date":event["date"],"event":"received"}) + except: + pass + try: + if event["lost"]: + for card in event["lost"]: + if card[:-2] == deck: + deckdates.append({"card":card,"date":event["date"],"event":"lost"}) + except: + pass + cards = {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:0,20:0} + mastered = False + for event in deckdates: + if not mastered: + if event["event"] == "received": + cards[int(event["card"][-2:])] += 1 + if event["event"] == "lost": + cards[int(event["card"][-2:])] -= 1 + if cards[1] > 0 and cards[2] > 0 and cards[3] > 0 and cards[4] > 0 and cards[5] > 0 and cards[6] > 0 and cards[7] > 0 and cards[8] > 0 and cards[9] > 0 and cards[10] > 0 and cards[11] > 0 and cards[12] > 0 and cards[13] > 0 and cards[14] > 0 and cards[15] > 0 and cards[16] > 0 and cards[17] > 0 and cards[18] > 0 and cards[19] > 0 and cards[20] > 0: + mastered = event["date"] + return mastered + def collecting(deck): if len (deckcards(deck)) < 20: if deck in variables.highpriority: @@ -94,8 +124,12 @@ def printdeck(deck): deckstring = "\n\n \n \n \n\n\n" + deckstring += decktype + "\">\n\n \n \n \n\n\n" test = 1 while test < 21: if test % 5 == 1: diff --git a/tradegen.py b/tradegen.py index 766a2ae..f5df772 100644 --- a/tradegen.py +++ b/tradegen.py @@ -30,12 +30,13 @@ def tradegen(colour=False): else: content.write(tcgcore.printcard(card)) else: - if not tcgcore.collecting(card[:-2]): - if colour: - if tcgcore.cardtype(card) == colour: + if not tcgcore.deckmastered(card[:-2]): + if not tcgcore.collecting(card[:-2]): + if colour: + if tcgcore.cardtype(card) == colour: + content.write(tcgcore.printcard(card)) + else: content.write(tcgcore.printcard(card)) - else: - content.write(tcgcore.printcard(card)) previouscard = card siglist = [] for card in tcgcore.ownedcards(): diff --git a/variables-template.py b/variables-template.py index af7ca41..d442cee 100644 --- a/variables-template.py +++ b/variables-template.py @@ -10,3 +10,4 @@ british = True collectthreshold = 2 keepsig = False tradestatement = "" +maxmastered = 20
" + deck + " [" - deckstring += str(len(deckcards(deck))) + "/20]
" + deck + if deckmastered(deck): + deckstring += " [" + datemastered(deck).strftime("%Y-%m-%d") + "]" + else: + deckstring += " [" + str(len(deckcards(deck))) + "/20]" + deckstring += "