Compare commits

...

3 Commits

@ -46,5 +46,5 @@ Python scripts to generate a mobile-friendly static site for tracking tcg cards
- Add level images manually to =build/assets/levels/=
- Add custom CSS to =build/user.css=
*** Updating and building
- For each transaction, add a dictionary ={}= to the =log= list like in the example (removing any of ="received"=, ="lost"=, ="crayons"=, ="decks"=, ="coupons">= that arent relevant).
- For each transaction, add a dictionary ={}= to the =log= list like in the example (removing any of ="received"=, ="lost"=, ="crayons"=, ="decks"=, ="coupons"=, ="pend"=, ="unpend"= that arent relevant).
- Run =./build.sh= in this directory to download the relevant card images and then upload everything to the server.

@ -563,7 +563,27 @@ span.searchresults {
font-family: monospace;
}
/* coupons */
img.coupon.expired {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
}
/* pending cards */
td:has(.pending) {
position: relative;
}
td:has(.pending) img {
filter: hue-rotate(180deg);
}
td p.pending {
position: absolute;
font-size: 10px;
top: 50%;
left: 50%;
transform: translate(-50%, -200%);
}

@ -9,6 +9,8 @@ log = [
"crayons":{"red":1,"orange":2,"yellow":-3},
"coupons":{"01":5},
"decks":["deck1","deck2","deck3","deck4","deck5","deck6","deck7","deck8"], # only if "event":"portfolio"
"sketch":-1 # for turning in 1 sketchpad
"sketch":-1, # for turning in 1 sketchpad
"pend":["card05"], # to mark a card as pending
"unpend":["card06"] # to remove a card from the pending list if a trade is cancelled
}
]

142
new.py

@ -8,7 +8,7 @@ numbers = ["01","02","03","04","05","06","07","08","09","10","11","12","13","14"
print("Getting list of deck colours")
deckkey = []
deckkey = {}
request = requests.get("https://colors-tcg.eu/cards.php?view=alpha")
alldecks = open("key.html","w")
@ -31,10 +31,8 @@ for row in souprows:
soupcells = row.find_all("td")
deckname = soupcells[2].text.lower().replace(" ","").replace("'","").replace("ç","c").replace(".","").replace("politetness","politeness")
decktype = soupcells[3].text.lower()
thedeck = {}
thedeck[deckname] = decktype
if decktype in values:
deckkey.append(thedeck)
deckkey[deckname] = decktype
print("Parsing log")
@ -54,6 +52,7 @@ redeemedsketch = 0
coupons = []
datelist = []
logitems = []
pends = []
for event in log.log:
logentry = {}
@ -66,10 +65,7 @@ for event in log.log:
thedecks = {}
for spacedeck in event["decks"]:
deck = spacedeck.replace(" ","")
for keydeck in deckkey:
if deck in keydeck:
thedecks[spacedeck] = keydeck[deck]
break
thedecks[spacedeck] = deckkey[deck]
portcolours = list(thedecks.values())
portcolours = sorted(list(dict.fromkeys(portcolours)))
if len(portcolours) < 3:
@ -106,10 +102,10 @@ for event in log.log:
if card[0:4] == "sig_":
thecard["colour"] = "sig"
else:
for deck in deckkey:
if thedeck in deck:
thecard["colour"] = deck[thedeck]
break
try:
thecard["colour"] = deckkey[thedeck]
except:
pass
try:
if thecard["colour"]:
pass
@ -237,6 +233,16 @@ for event in log.log:
coupons.append({newcoupon:event["coupons"][newcoupon]})
except:
pass
try:
for card in event["pend"]:
pends.append(card)
except:
pass
try:
for card in event["unpend"]:
pends.remove(card)
except:
pass
if logit == True:
logitems.append(logentry)
@ -268,10 +274,7 @@ decklist = []
for deck in decks:
thedeck = {}
thedeck["name"] = deck
for keydeck in deckkey:
if deck in keydeck:
thedeck["colour"] = keydeck[deck]
break
thedeck["colour"] = deckkey[deck]
thedeck["mass"] = []
thedeck["massmaster"] = []
for theme in variables.masscollect:
@ -346,11 +349,50 @@ for deck in decklist:
for number in numbers:
if deck[number] == None:
wantedcard = {}
wantedcard["name"] = deck["name"] + str(number)
wantedcard["name"] = deck["name"] + number
wantedcard["colour"] = deck["colour"]
wantedcard["priority"] = deck["priority"]
wantedlist.append(wantedcard)
decknames = []
for deck in decklist:
decknames.append(deck["name"])
for theme in variables.masscollect:
if variables.masscollect[theme]["full"] == True:
try:
for deck in variables.masscollect[theme]["decks"]:
if deck not in decknames:
for number in numbers:
wantedcard = {}
wantedcard["name"] = deck + number
wantedcard["colour"] = deckkey[deck]
wantedcard["priority"] = 3
wantedlist.append(wantedcard)
except KeyError:
pass
try:
for card in variables.masscollect[theme]["singles"]:
if card[:-2] not in decknames:
wantedcard = {}
wantedcard["name"] = card
wantedcard["colour"] = deckkey[card[:-2]]
wantedcard["priority"] = 3
wantedlist.append(wantedcard)
except KeyError:
pass
wantedlist = sorted(wantedlist, key=lambda d: d["name"])
removelist = []
for card in wantedlist:
if card["name"] in pends:
removelist.append(card)
for card in removelist:
wantedlist.remove(card)
print("Adjusting card priorities")
for card in cardlist:
@ -442,12 +484,20 @@ def footerwrite(thefile):
footer.close()
def printcard(card):
if card["colour"] == "sig":
return "<img src=\"/decks/sigs/" + card["name"][4:] + ".gif\" title=\"" + card["name"] + "\" loading=\"lazy\">"
else:
deck = card["name"][:-2]
cardid = card["name"][-2:]
return "<img src=\"/decks/" + deck + "/" + cardid + ".gif\" title=\"" + card["name"] + "\" loading=\"lazy\">"
if type(card) == dict:
if card["colour"] == "sig":
return "<img src=\"/decks/sigs/" + card["name"][4:] + ".gif\" title=\"" + card["name"] + "\" loading=\"lazy\">"
else:
deck = card["name"][:-2]
cardid = card["name"][-2:]
return "<img src=\"/decks/" + deck + "/" + cardid + ".gif\" title=\"" + card["name"] + "\" loading=\"lazy\">"
elif type(card) == str:
if card[0:4] == "sig_":
return "<img src=\"/decks/sigs/" + card[4:] + ".gif\" title=\"" + card + "\" loading=\"lazy\">"
else:
deck = card[:-2]
cardid = card[-2:]
return "<img src=\"/decks/" + deck + "/" + cardid + ".gif\" title=\"" + card + "\" loading=\"lazy\">"
def cardtext(card):
cardtext = "<span class=\"cardname\">"
@ -807,6 +857,8 @@ def printdeck(deck,fold=True):
break
if found == False:
deckstring += "<img src=\"/decks/" + deck["name"] + "/00.gif\" loading=\"lazy\">"
if deck["name"] + teststring in pends:
deckstring += "<p class=\"pending\">pending</p>"
deckstring += "</td>\n"
if test % 5 == 0:
deckstring += " </tr>\n"
@ -1074,10 +1126,7 @@ def indexgen():
content.write("<h2>faves</h2>\n<p>")
faveslist = sorted(variables.faves)
for card in faveslist:
for thecard in cardlist:
if card == thecard["name"]:
content.write(printcard(thecard))
break
content.write(printcard(card))
content.write("</p>\n")
if len(coupons) > 0:
content.write("<h2>coupons</h2>\n<p>")
@ -1092,26 +1141,43 @@ def indexgen():
content.write("</p>\n")
donations = []
try:
for deck in variables.donations["decks"]:
donations.append(deck + "00")
for donatedeck in variables.donations["decks"]:
donation = {}
donation["name"] = donatedeck
for deck in decklist:
if deck["name"] == donatedeck:
if deck["mastered"]:
donation["type"] = "mastered"
else:
donation["type"] = "deck"
break
donations.append(donation)
except:
pass
try:
for card in variables.donations["scrapbook"]:
donations.append(card)
donation = {}
donation["name"] = card
donation["type"] = "single"
donations.append(donation)
except:
pass
if len(donations) > 0:
donations = sorted(donations)
donations = sorted(donations, key=lambda d: d["name"])
content.write("<h2>donations</h2>\n<p>")
for donation in donations:
if donation[-2:] == "00":
content.write("<img src=\"/decks/" + donation[:-2] + "/00.gif\" loading=\"lazy\">")
else:
for thecard in cardlist:
if donation == thecard["name"]:
content.write(printcard(thecard))
break
if donation["type"] == "deck":
content.write("<img src=\"/decks/" + donation["name"] + "/00.gif\" loading=\"lazy\">")
elif donation["type"] == "mastered":
content.write("<img src=\"/decks/" + donation["name"] + "/master.gif\" title=\"mastered " + donation["name"])
try:
if donation["name"] in variables.firstmasteries:
content.write(" (first)\" class=\"first")
except:
pass
content.write("\">")
elif donation["type"] == "single":
content.write(printcard(donation["name"]))
content.write("</p>\n")
content.close()
footerwrite(thefile)

Loading…
Cancel
Save