mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
script that clears old setinfo and rarity and assigns new one based on mtg-data.txt
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -13,6 +13,7 @@
|
||||
/pom.xml svneol=native#text/xml
|
||||
res/AllTokens.txt svneol=native#text/plain
|
||||
res/PerSetTracking.py svneol=native#text/x-python
|
||||
res/assignSetInfo.py -text
|
||||
res/blockdata/blocks.txt svneol=native#text/plain
|
||||
res/blockdata/boosters.txt -text
|
||||
res/blockdata/fantasyblocks.txt -text
|
||||
@@ -12424,6 +12425,7 @@ res/licenses/multiline-label-license.txt svneol=native#text/plain
|
||||
res/licenses/xpp3-license.txt svneol=native#text/plain
|
||||
res/licenses/xstream-license.txt svneol=native#text/plain
|
||||
res/mtg-data.txt svneol=native#text/plain
|
||||
res/mtgdata-sets-to-forge.txt -text
|
||||
res/oracleScript.py -text svneol=unset#text/x-python
|
||||
res/pics_link/card-pictures_a.txt svneol=native#text/plain
|
||||
res/pics_link/card-pictures_b.txt svneol=native#text/plain
|
||||
|
||||
142
res/assignSetInfo.py
Normal file
142
res/assignSetInfo.py
Normal file
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os,sys,fnmatch,re
|
||||
|
||||
pathToMtgData = "mtg-data.txt"
|
||||
pathToSetsMatchTable = "mtgdata-sets-to-forge.txt"
|
||||
|
||||
class cis: # CardInSet
|
||||
def __init__(self):
|
||||
self.edition = ""
|
||||
self.rarity = "C"
|
||||
self.arts = 1
|
||||
|
||||
def __str__(self):
|
||||
return "{} {} {}".format(self.edition, self.rarity, self.arts)
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
|
||||
def rarityFull(self):
|
||||
if (self.rarity == "B"):
|
||||
return "Land"
|
||||
if (self.rarity == "R"):
|
||||
return "Rare"
|
||||
if (self.rarity == "U"):
|
||||
return "Uncommon"
|
||||
if (self.rarity == "S"):
|
||||
return "Special"
|
||||
if (self.rarity == "M"):
|
||||
return "Mythic"
|
||||
return "Common"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not os.path.exists(pathToMtgData) :
|
||||
print("This script requires the text version of Arch's mtg-data to be present.You can download it from slightlymagic.net's forum and either place the text version next to this script or edit this script and provide the path to the file at the top.")
|
||||
print("Press Enter to exit")
|
||||
raw_input("")
|
||||
sys.exit()
|
||||
|
||||
setCodes = []
|
||||
setCodeToName = {}
|
||||
setCodeToForge = {}
|
||||
mtgDataCards = {}
|
||||
|
||||
|
||||
hasFetchedSets = False
|
||||
hasFetchedCardName = False
|
||||
tmpName = ""
|
||||
line = ""
|
||||
prevline = ""
|
||||
|
||||
#Parse mtg-data
|
||||
print("Parsing mtg-data...")
|
||||
with open(pathToMtgData) as mtgdata :
|
||||
for line in mtgdata :
|
||||
# Parse the sets at the top of the mtgdata file
|
||||
if not hasFetchedSets :
|
||||
if line != "\n" :
|
||||
splitLine = line.split(' ')
|
||||
code = splitLine[0]
|
||||
setCodeToName[code] = splitLine[-1].replace('\n', '')
|
||||
#print splitLine, code, setCodeToName[code]
|
||||
setCodes.append(code)
|
||||
else :
|
||||
hasFetchedSets = True
|
||||
|
||||
# Once all sets are parsed, time to parse the cards
|
||||
elif hasFetchedSets :
|
||||
if not hasFetchedCardName :
|
||||
tmpName = line.rstrip()
|
||||
hasFetchedCardName = True
|
||||
oracle = ""
|
||||
|
||||
else:
|
||||
oracle += line
|
||||
|
||||
if line == "\n" :
|
||||
#mtgOracleCards[tmpName] = oracle.replace(prevline, '')
|
||||
|
||||
sets = prevline.split(", ")
|
||||
editions = []
|
||||
for i in range(len(sets)):
|
||||
ee = sets[i].split(' ')
|
||||
editions.append(cis())
|
||||
editions[i].edition = ee[0]
|
||||
editions[i].rarity = ee[1]
|
||||
if len(ee) > 2:
|
||||
editions[i].arts = int(ee[2][2:3])
|
||||
#print sets
|
||||
mtgDataCards[tmpName] = editions
|
||||
hasFetchedCardName = False
|
||||
|
||||
prevline = line
|
||||
|
||||
|
||||
print("Matching mtg-data and Forge sets")
|
||||
with open(pathToSetsMatchTable) as setsMatch :
|
||||
for line in setsMatch:
|
||||
if line[0:3] == "---":
|
||||
code = line[3:].split(" ")[0]
|
||||
setCodeToForge[code] = None
|
||||
|
||||
elif line[0:3] == "===":
|
||||
code = line[3:].split(" ")[0]
|
||||
setCodeToForge[code] = code;
|
||||
else:
|
||||
code1 = line.split(" ")[0]
|
||||
code2 = line.split(" ")[1]
|
||||
setCodeToForge[code1] = code2
|
||||
|
||||
|
||||
folder = "cardsfolder"
|
||||
for root, dirnames, filenames in os.walk(folder):
|
||||
for fileName in fnmatch.filter(filenames, '*.txt'):
|
||||
if fileName.startswith('.'):
|
||||
continue
|
||||
|
||||
cardfile = open(os.path.join(root, fileName), 'r')
|
||||
|
||||
firstLine = cardfile.readline().strip()
|
||||
cardName = firstLine[5:]
|
||||
|
||||
print (cardName, fileName)
|
||||
validLines = []
|
||||
validLines.append(firstLine)
|
||||
|
||||
for line in cardfile.readlines():
|
||||
if line[:8] != "SetInfo:" and line[:8] != "SVar:Rar":
|
||||
validLines.append(line.strip())
|
||||
cardfile.close()
|
||||
|
||||
for e in mtgDataCards[cardName]:
|
||||
if not setCodeToForge[e.edition] is None:
|
||||
validLines.append( ("SetInfo:{} {}" if e.arts <= 1 else "SetInfo:{} {} x{}" ).format(setCodeToForge[e.edition], e.rarityFull(), e.arts) )
|
||||
|
||||
toWrite = "\n".join(validLines)
|
||||
|
||||
cardfile = open(os.path.join(root, fileName), 'w')
|
||||
cardfile.write(toWrite)
|
||||
cardfile.close();
|
||||
|
||||
117
res/mtgdata-sets-to-forge.txt
Normal file
117
res/mtgdata-sets-to-forge.txt
Normal file
@@ -0,0 +1,117 @@
|
||||
===10E # Tenth Edition
|
||||
1E LEA # Limited Edition Alpha
|
||||
2E LEB # Limited Edition Beta
|
||||
2U 2ED # Unlimited Edition
|
||||
3E 3ED # Revised Edition
|
||||
4E 4ED # Fourth Edition
|
||||
===5DN # Fifth Dawn
|
||||
5E 5ED # Fifth Edition
|
||||
6E 6ED # Classic Sixth Edition
|
||||
7E 7ED # Seventh Edition
|
||||
===8ED # Eighth Edition
|
||||
===9ED # Ninth Edition
|
||||
AL ALL # Alliances
|
||||
===ALA # Shards of Alara
|
||||
AN ARN # Arabian Nights
|
||||
AP APC # Apocalypse
|
||||
AQ ATQ # Antiquities
|
||||
===ARB # Alara Reborn
|
||||
===ARC # Archenemy
|
||||
---ASTRAL # Astral
|
||||
===AVR # Avacyn Restored
|
||||
---BD # Beatdown Box Set
|
||||
===BOK # Betrayers of Kamigawa
|
||||
---BR # Battle Royale Box Set
|
||||
CG UDS # Urza's Destiny
|
||||
CH CHR # Chronicles
|
||||
===CHK # Champions of Kamigawa
|
||||
---CM1 # Commander's Arsenal
|
||||
===CMD # Magic: The Gathering-Commander
|
||||
CON CFX # Conflux
|
||||
===CSP # Coldsnap
|
||||
===DD2 # Duel Decks: Jace vs. Chandra
|
||||
===DDC # Duel Decks: Divine vs. Demonic
|
||||
===DDD # Duel Decks: Garruk vs. Liliana
|
||||
===DDE # Duel Decks: Phyrexia vs. the Coalition
|
||||
===DDF # Duel Decks: Elspeth vs. Tezzeret
|
||||
===DDG # Duel Decks: Knights vs. Dragons
|
||||
===DDH # Duel Decks: Ajani vs. Nicol Bolas
|
||||
===DDI # Duel Decks: Venser vs. Koth
|
||||
===DDJ # Duel Decks: Izzet vs. Golgari
|
||||
===DIS # Dissension
|
||||
DK DRK # The Dark
|
||||
===DKA # Dark Ascension
|
||||
===DRB # From the Vault: Dragons
|
||||
---DREAM # Dreamcast
|
||||
===DST # Darksteel
|
||||
===EVE # Eventide
|
||||
===EVG # Duel Decks: Elves vs. Goblins
|
||||
EX EXO # Exodus
|
||||
FE FEM # Fallen Empires
|
||||
===FUT # Future Sight
|
||||
===GPT # Guildpact
|
||||
===GTC # Gatecrash
|
||||
GU ULG # Urza's Legacy
|
||||
===H09 # Premium Deck Series: Slivers
|
||||
HM HML # Homelands
|
||||
===HOP # Planechase
|
||||
IA ICE # Ice Age
|
||||
IN INV # Invasion
|
||||
===ISD # Innistrad
|
||||
===JUD # Judgment
|
||||
LE LEG # Legends
|
||||
===LGN # Legions
|
||||
===LRW # Lorwyn
|
||||
===M10 # Magic 2010
|
||||
===M11 # Magic 2011
|
||||
===M12 # Magic 2012
|
||||
===M13 # Magic 2013
|
||||
===MBS # Mirrodin Besieged
|
||||
---ME2 # Masters Edition II
|
||||
---ME3 # Masters Edition III
|
||||
---ME4 # Masters Edition IV
|
||||
---MED # Masters Edition
|
||||
MI MIR # Mirage
|
||||
MM MMQ # Mercadian Masques
|
||||
===MOR # Morningtide
|
||||
===MRD # Mirrodin
|
||||
NE NMS # Nemesis
|
||||
===NPH # New Phyrexia
|
||||
OD ODY # Odyssey
|
||||
===ONS # Onslaught
|
||||
P2 PO2 # Portal Second Age
|
||||
P3 S99 # Starter 1999
|
||||
P4 S00 # Starter 2000
|
||||
===PC2 # Planechase 2012 Edition
|
||||
===PD2 # Premium Deck Series: Fire and Lightning
|
||||
===PD3 # Premium Deck Series: Graveborn
|
||||
PK PTK # Portal Three Kingdoms
|
||||
===PLC # Planar Chaos
|
||||
PO POR # Portal
|
||||
---PPR # Promo set for Gatherer
|
||||
PR PCY # Prophecy
|
||||
PS PLS # Planeshift
|
||||
===RAV # Ravnica: City of Guilds
|
||||
===ROE # Rise of the Eldrazi
|
||||
===RTR # Return to Ravnica
|
||||
===SCG # Scourge
|
||||
===SHM # Shadowmoor
|
||||
===SOK # Saviors of Kamigawa
|
||||
===SOM # Scars of Mirrodin
|
||||
ST STH # Stronghold
|
||||
TE TMP # Tempest
|
||||
===TOR # Torment
|
||||
===TSB # Time Spiral "Timeshifted"
|
||||
===TSP # Time Spiral
|
||||
---UG # Unglued
|
||||
---UNH # Unhinged
|
||||
UZ USG # Urza's Saga
|
||||
===V09 # From the Vault: Exiled
|
||||
===V10 # From the Vault: Relics
|
||||
===V11 # From the Vault: Legends
|
||||
===V12 # From the Vault: Realms
|
||||
===VAN # Vanguard
|
||||
VI VIS # Visions
|
||||
WL WTH # Weatherlight
|
||||
===WWK # Worldwake
|
||||
===ZEN # Zendikar
|
||||
Reference in New Issue
Block a user