sorting csv by set and card id

This commit is contained in:
Caleb Fultz 2024-08-13 16:25:54 -04:00
parent a4ea3fa106
commit 8c45c0e501
2 changed files with 58 additions and 30 deletions

View File

@ -1,38 +1,48 @@
Card Name,Set Code,Collector Number,Quantity,Foil
"Flubs, The Fool",blc,356,1,True
"Flubs, The Fool",blc,356,1,False
Skemfar Shadowsage,sld,759,3,True
Pollenbright Druid,sld,776,1,True
Timberwatch Elf,sld,780,2,True
Frilled Mystic,sld,786,1,True
Coveted Jewel,sld,799,1,False
The Scorpion God,sld,904,1,True
"Linda, Kandarian Queen",sld,1355,1,True
"Vraska, Golgari Queen",sld,1702,1,False
"Vraska, Golgari Queen",sld,1702,1,True
Felidar Guardian,sld,1487,1,False
Peregrine Drake,sld,1488,1,False
Serpent of Yawning Depths,sld,1489,1,False
Scourage of Valkas,sld,1490,1,False
Voracious Hydra,sld,1491,1,False
Wall of Omens,sld,1518,1,False
Circular Logic,sld,1519,1,False
Scheming Symmentry,sld,1520,1,False
Price of Progress,sld,1521,1,False
Eternal Witness,sld,1522,1,False
Sakashima of a Thousand Faces,sld,1541,1,False
"Yargle, Glutton of Urborg",sld,1542,1,False
"Krark, The Thumbless",sld,1543,1,False
"Adrix and Nev, Twincasters",sld,1544,1,False
Arcance Denial,sld,1545,1,False
Nightscape Familiar,sld,1546,1,False
Rain of Filth,sld,1547,1,False
Simian Spirit Guide,sld,1548,1,False
Prince of Thralls,sld,1549,1,False
"Gonti, Lord of Luxury",sld,1566,1,False
"Vilis, Broker of Blood",sld,1567,1,False
"Anowon, the Ruin Thief",sld,1568,1,False
"Grenzo, Dungeon Warden",sld,1569,1,False
Reconnasissance,sld,1575,1,False
"Jace, Wielder of Mysteries",sld,1576,1,False
Black Market,sld,1577,1,False
Dire Undercurrents,sld,1578,1,False
"Obeka, Brute Chronolgoist",sld,1579,1,False
Sorin Markov,sld,1698,1,False
Sorin Markov,sld,1698,1,True
"Huatli, Radiant Champion",sld,1699,1,False
"Huatli, Radiant Champion",sld,1699,1,True
"Kiora, Behemoth Beckoner",sld,1700,1,False
"Kiora, Behemoth Beckoner",sld,1700,1,True
"Tezzeret, Master of the Bridge",sld,1701,1,False
"Tezzeret, Master of the Bridge",sld,1701,1,True
Sorin Markov,sld,1698,1,False
Sorin Markov,sld,1698,1,True
"Flubs, The Fool",blc,356,1,True
"Flubs, The Fool",blc,356,1,False
Pollenbright Druid,sld,776,1,True
Frilled Mystic,sld,786,1,True
"Obeka, Brute Chronolgoist",sld,1579,1,False
Dire Undercurrents,sld,1578,1,False
Black Market,sld,1577,1,False
"Jace, Wielder of Mysteries",sld,1576,1,False
Reconnasissance,sld,1575,1,False
"Yargle, Glutton of Urborg",sld,1542,1,False
"Adrix and Nev, Twincasters",sld,1544,1,False
Coveted Jewel,sld,799,1,False
Sakashima of a Thousand Faces,sld,1541,1,False
"Krark, The Thumbless",sld,1543,1,False
Arcance Denial,sld,1545,1,False
Nightscape Familiar,sld,1546,1,False
Rain of Filth,sld,1547,1,False
Simian Spirit Guide,sld,1548,1,False
Prince of Thralls,sld,1549,1,False
Felidar Guardian,sld,1487,1,False
Peregrine Drake,sld,1488,1,False
Serpent of Yawning Depths,sld,1489,1,False
Scourage of Valkas,sld,1490,1,False
Voracious Hydra,sld,1491,1,False
The Scorpion God,sld,904,1,True
"Vilis, Broker of Blood",sld,1567,1,False
"Vraska, Golgari Queen",sld,1702,1,False
"Vraska, Golgari Queen",sld,1702,1,True

1 Card Name Set Code Collector Number Quantity Foil
2 Flubs, The Fool blc 356 1 True
3 Flubs, The Fool blc 356 1 False
4 Skemfar Shadowsage sld 759 3 True
5 Pollenbright Druid sld 776 1 True
6 Timberwatch Elf sld 780 2 True
7 Frilled Mystic sld 786 1 True
8 Coveted Jewel sld 799 1 False
9 The Scorpion God sld 904 1 True
10 Linda, Kandarian Queen sld 1355 1 True
11 Vraska, Golgari Queen Felidar Guardian sld 1702 1487 1 False
12 Vraska, Golgari Queen Peregrine Drake sld 1702 1488 1 True False
13 Serpent of Yawning Depths sld 1489 1 False
14 Scourage of Valkas sld 1490 1 False
15 Voracious Hydra sld 1491 1 False
16 Wall of Omens sld 1518 1 False
17 Circular Logic sld 1519 1 False
18 Scheming Symmentry sld 1520 1 False
19 Price of Progress sld 1521 1 False
20 Eternal Witness sld 1522 1 False
21 Sakashima of a Thousand Faces sld 1541 1 False
22 Yargle, Glutton of Urborg sld 1542 1 False
23 Krark, The Thumbless sld 1543 1 False
24 Adrix and Nev, Twincasters sld 1544 1 False
25 Arcance Denial sld 1545 1 False
26 Nightscape Familiar sld 1546 1 False
27 Rain of Filth sld 1547 1 False
28 Simian Spirit Guide sld 1548 1 False
29 Prince of Thralls sld 1549 1 False
30 Gonti, Lord of Luxury sld 1566 1 False
31 Vilis, Broker of Blood sld 1567 1 False
32 Anowon, the Ruin Thief sld 1568 1 False
33 Grenzo, Dungeon Warden sld 1569 1 False
34 Reconnasissance sld 1575 1 False
35 Jace, Wielder of Mysteries sld 1576 1 False
36 Black Market sld 1577 1 False
37 Dire Undercurrents sld 1578 1 False
38 Obeka, Brute Chronolgoist sld 1579 1 False
39 Sorin Markov sld 1698 1 False
40 Sorin Markov sld 1698 1 True
41 Huatli, Radiant Champion sld 1699 1 False
42 Huatli, Radiant Champion sld 1699 1 True
43 Kiora, Behemoth Beckoner sld 1700 1 False
44 Kiora, Behemoth Beckoner sld 1700 1 True
45 Tezzeret, Master of the Bridge sld 1701 1 False
46 Tezzeret, Master of the Bridge sld 1701 1 True
47 Sorin Markov Vraska, Golgari Queen sld 1698 1702 1 False
48 Sorin Markov Vraska, Golgari Queen sld 1698 1702 1 True
Flubs, The Fool blc 356 1 True
Flubs, The Fool blc 356 1 False
Pollenbright Druid sld 776 1 True
Frilled Mystic sld 786 1 True
Obeka, Brute Chronolgoist sld 1579 1 False
Dire Undercurrents sld 1578 1 False
Black Market sld 1577 1 False
Jace, Wielder of Mysteries sld 1576 1 False
Reconnasissance sld 1575 1 False
Yargle, Glutton of Urborg sld 1542 1 False
Adrix and Nev, Twincasters sld 1544 1 False
Coveted Jewel sld 799 1 False
Sakashima of a Thousand Faces sld 1541 1 False
Krark, The Thumbless sld 1543 1 False
Arcance Denial sld 1545 1 False
Nightscape Familiar sld 1546 1 False
Rain of Filth sld 1547 1 False
Simian Spirit Guide sld 1548 1 False
Prince of Thralls sld 1549 1 False
Felidar Guardian sld 1487 1 False
Peregrine Drake sld 1488 1 False
Serpent of Yawning Depths sld 1489 1 False
Scourage of Valkas sld 1490 1 False
Voracious Hydra sld 1491 1 False
The Scorpion God sld 904 1 True
Vilis, Broker of Blood sld 1567 1 False

View File

@ -17,6 +17,21 @@ def add_card_to_csv(csv_path, card_name, set_code, collector_number, quantity, f
print(f"Added {quantity}x {card_name} from set {set_code} with collector number {collector_number} (Foil: {foil}) to {csv_path}.")
# Function to sort the CSV file by Set Code and Collector Number
def sort_csv_file(csv_path):
with open(csv_path, mode='r') as file:
reader = csv.reader(file)
header = next(reader) # Read the header
sorted_rows = sorted(reader, key=lambda row: (row[1], int(row[2]))) # Sort by Set Code (row[1]) and Collector Number (row[2])
# Write the sorted data back to the CSV
with open(csv_path, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(header) # Write the header back
writer.writerows(sorted_rows) # Write the sorted rows
print(f"CSV file sorted by Set Code and Collector Number.")
# Function to get user input and add multiple cards interactively
def interactive_card_entry(csv_path):
while True:
@ -34,6 +49,9 @@ def interactive_card_entry(csv_path):
# Add the card to the CSV file
add_card_to_csv(csv_path, card_name, set_code, collector_number, quantity, foil)
# Sort the CSV file after each entry
sort_csv_file(csv_path)
if __name__ == "__main__":
csv_path = input("Enter the path to the CSV file: ").strip()
interactive_card_entry(csv_path)