From 63d654bd8a1b46b2072d937adf7961f16aebe871 Mon Sep 17 00:00:00 2001 From: Mez Date: Sun, 3 Aug 2025 22:06:16 +0100 Subject: [PATCH] Add natsume function --- tools.py | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 1 deletion(-) diff --git a/tools.py b/tools.py index d6adaed..856be72 100644 --- a/tools.py +++ b/tools.py @@ -1659,12 +1659,150 @@ def roulette(): letteurl = input("Comment URL: ") print("\n{\"event\":\"release roulette " + theround + "\",\"date\":datetime.datetime(" + datetime.datetime.now().strftime("%Y,%-m,%-d") + "),\"url\":\"" + letteurl + "\",\"lost\":[\"" + "\",\"".join(chosen) + "\"]}") +def natsume(): + natsudecks = input("Paste in list of decks: ").split(", ") + natsuwant = [] + natsugivech = [] + natsugivesp = [] + for card in colors.cardlist: + for deck in natsudecks: + for number in colors.numbers: + if card["name"] == deck + number: + if card["priority"] > 2: + if card["colour"] == "special": + natsugivesp.append(card) + else: + natsugivech.append(card) + for card in colors.wantedlist: + for deck in natsudecks: + for number in colors.numbers: + if card["name"] == deck + number: + natsuwant.append(card) + for card in natsugivech: + count = 0 + for othercard in natsugivech: + if othercard["name"][:-2] == card["name"][:-2]: + count += 1 + card["count"] = count + natsugivech = sorted(natsugivech, key=lambda d: d["count"],reverse=True) + natsugivech = sorted(natsugivech, key=lambda d: d["priority"],reverse=True) + for card in natsugivesp: + count = 0 + for othercard in natsugivesp: + if othercard["name"][:-2] == card["name"][:-2]: + count += 1 + card["count"] = count + natsugivesp = sorted(natsugivesp, key=lambda d: d["count"],reverse=True) + natsugivesp = sorted(natsugivesp, key=lambda d: d["priority"],reverse=True) + natsuwantgrouped = [] + natsugivechgrouped = [] + natsugivespgrouped = [] + index = 0 + for card in natsuwant: + if index > 0: + if card["name"][:-2] == natsuwant[index-1]["name"][:-2]: + listone.append(card) + if index + 1 == len(natsuwant): + natsuwantgrouped.append(listone) + else: + natsuwantgrouped.append(listone) + listone = [] + listone.append(card) + else: + listone = [] + listone.append(card) + index += 1 + index = 0 + for card in natsugivech: + if index > 0: + if card["name"][:-2] == natsugivech[index-1]["name"][:-2]: + listtwo.append(card["name"]) + if index + 1 == len(natsugivech): + natsugivechgrouped.append(listtwo) + else: + natsugivechgrouped.append(listtwo) + listtwo = [] + listtwo.append(card["name"]) + else: + listtwo = [] + listtwo.append(card["name"]) + index += 1 + index = 0 + for card in natsugivesp: + if index > 0: + if card["name"][:-2] == natsugivesp[index-1]["name"][:-2]: + listthree.append(card["name"]) + if index + 1 == len(natsugivesp): + natsugivespgrouped.append(listthree) + else: + natsugivespgrouped.append(listthree) + listthree = [] + listthree.append(card["name"]) + else: + listthree = [] + listthree.append(card["name"]) + index += 1 + natsugivechgrouped = natsugivechgrouped[:5] + natsugivespgrouped = natsugivespgrouped[:5] + finalwant = [] + finalgive = [] + for group in natsuwantgrouped: + if len(finalwant) < 5: + if group[0]["colour"] == "special": + if len(natsugivespgrouped) > 0: + if natsugivespgrouped[0][0][:-2] == group[0]["name"][:-2]: + if len(natsugivespgrouped) > 1: + group = group[:len(natsugivespgrouped[1])] + natsugivespgrouped[1] = natsugivespgrouped[1][:len(group)] + for givecard in natsugivespgrouped[1]: + finalgive.append(givecard) + natsugivespgrouped.pop(1) + for card in group: + finalwant.append(card["name"]) + else: + group = group[:len(natsugivespgrouped[0])] + natsugivespgrouped[0] = natsugivespgrouped[0][:len(group)] + for givecard in natsugivespgrouped[0]: + finalgive.append(givecard) + natsugivespgrouped.pop(0) + for card in group: + finalwant.append(card["name"]) + else: + if len(natsugivechgrouped) > 0: + if natsugivechgrouped[0][0][:-2] == group[0]["name"][:-2]: + if len(natsugivechgrouped) > 1: + group = group[:len(natsugivechgrouped[1])] + natsugivechgrouped[1] = natsugivechgrouped[1][:len(group)] + for givecard in natsugivechgrouped[1]: + finalgive.append(givecard) + natsugivechgrouped.pop(1) + for card in group: + finalwant.append(card["name"]) + else: + group = group[:len(natsugivechgrouped[0])] + natsugivechgrouped[0] = natsugivechgrouped[0][:len(group)] + for givecard in natsugivechgrouped[0]: + finalgive.append(givecard) + natsugivechgrouped.pop(0) + for card in group: + finalwant.append(card["name"]) + finalwant = finalwant[:5] + finalgive = finalgive[:5] + if len(finalwant) > 0: + print("\nName: " + variables.name + "\nCards you are turning in (" + str(len(finalwant)) + "/5):\n\nCard names: " + ", ".join(finalgive) + "\nCards you want: " + ", ".join(finalwant)) + theround = input("\nRound number: ") + natsurl = input("Comment URL: ") + print("\n{\"event\":\"natsume’s book of cards " + theround + "\",\"date\":datetime.datetime(" + datetime.datetime.now().strftime("%Y,%-m,%-d") + "),\"url\":\"" + natsurl + "\",\"lost\":[\"" + "\",\"".join(finalgive) + "\"],\"received\":[\"" + "\",\"".join(finalwant) + "\"]}") + else: + print("Nothing can be swapped") + + if __name__ == "__main__": while True: index = 0 # adapted from https://stackoverflow.com/a/64536882 indexValidList = [] print("Choose from the list:") - options = ["Generate next palette portfolio","Generate next monochrome portfolio","Generate Switch It Up request","Generate Swap Station request","Generate Go Fish comment","Generate Release Roulette comment","Generate Riku’s Favors comment","Generate art shop request","Generate art studio request","Check a trade offer","Propose a trade","Get a list of random cards from tradepile (excluding specials)","Get a list of random cards from tradepile (including specials)","Check a card in the collection","Check details of a deck","See decks mastered today","See most wanted character cards","See most wanted special cards","See some statistics about the collection"] + options = ["Generate next palette portfolio","Generate next monochrome portfolio","Generate Switch It Up request","Generate Swap Station request","Generate Go Fish comment","Generate Release Roulette comment","Generate Riku’s Favors comment","Generate Natsume’s Book of Cards comment","Generate art shop request","Generate art studio request","Check a trade offer","Propose a trade","Get a list of random cards from tradepile (excluding specials)","Get a list of random cards from tradepile (including specials)","Check a card in the collection","Check details of a deck","See decks mastered today","See most wanted character cards","See most wanted special cards","See some statistics about the collection"] for optionName in options: index = index + 1 indexValidList.extend([options.index(optionName)]) @@ -1718,5 +1856,7 @@ if __name__ == "__main__": topwant() elif chosen == "See most wanted special cards": topwant(True) + elif chosen == "Generate Natsume’s Book of Cards comment": + natsume() print("\n") input("Press Enter to continue or Ctrl-C to exit")