Fix executable permissions. reprintSetInfo now takes a parameter for the set instead of it being hardcoded

This commit is contained in:
jendave
2011-08-07 01:56:01 +00:00
parent 41c299909e
commit ab8e166520
5 changed files with 504 additions and 499 deletions

6
.gitattributes vendored
View File

@@ -20,7 +20,7 @@ build/support/template.applescript -text
/forge.properties svneol=native#text/plain /forge.properties svneol=native#text/plain
/pom.xml svneol=native#text/xml /pom.xml svneol=native#text/xml
res/AllTokens.txt -text svneol=native#text/plain res/AllTokens.txt -text svneol=native#text/plain
res/PerSetTracking.py -text svneol=native#text/x-python res/PerSetTracking.py svneol=native#text/x-python
res/blockdata/blocks.txt svneol=native#text/plain res/blockdata/blocks.txt svneol=native#text/plain
res/blockdata/setdata.txt svneol=native#text/plain res/blockdata/setdata.txt svneol=native#text/plain
res/booster-decks -text svneol=unset#unset res/booster-decks -text svneol=unset#unset
@@ -8919,8 +8919,8 @@ res/quest/themes/White.thm -text
res/quest/themes/Wolves[!!-~]WG.thm -text res/quest/themes/Wolves[!!-~]WG.thm -text
res/quest/themes/Zombies[!!-~]B.thm -text res/quest/themes/Zombies[!!-~]B.thm -text
res/quest/veryhard.txt -text svneol=native#text/plain res/quest/veryhard.txt -text svneol=native#text/plain
res/reprintSetInfo.py -text svneol=native#text/x-python res/reprintSetInfo.py svneol=native#text/x-python
res/setInfoScript.py -text svneol=native#text/x-python res/setInfoScript.py svneol=native#text/x-python
res/sound/tap.mp3 -text svneol=unset#audio/mpeg res/sound/tap.mp3 -text svneol=unset#audio/mpeg
src/arcane/ui/CardArea.java svneol=native#text/plain src/arcane/ui/CardArea.java svneol=native#text/plain
src/arcane/ui/CardPanel.java svneol=native#text/plain src/arcane/ui/CardPanel.java svneol=native#text/plain

262
res/PerSetTracking.py Normal file → Executable file
View File

@@ -1,131 +1,131 @@
pathToMtgData = "mtg-data.txt" #!/usr/bin/env python
############IMPLEMENTATION FOLLOWS############ pathToMtgData = "mtg-data.txt"
import os,sys
############IMPLEMENTATION FOLLOWS############
if not os.path.exists(pathToMtgData) : import os,sys
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") if not os.path.exists(pathToMtgData) :
raw_input("") 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.")
sys.exit() print("Press Enter to exit")
raw_input("")
if not os.path.isdir(sys.path[0] + os.sep + 'PerSetTracking Results') : sys.exit()
os.mkdir(sys.path[0] + os.sep + 'PerSetTracking Results')
if not os.path.isdir(sys.path[0] + os.sep + 'PerSetTracking Results') :
forgeFolderContents = os.listdir(sys.path[0] + os.sep + "cardsfolder") os.mkdir(sys.path[0] + os.sep + 'PerSetTracking Results')
forgeFolderFiles = []
forgeCards = [] forgeFolderContents = os.listdir(sys.path[0] + os.sep + "cardsfolder")
mtgDataCards = {} forgeFolderFiles = []
setCodes = [] forgeCards = []
forgeCardCount = 0 mtgDataCards = {}
mtgDataCardCount = 0 setCodes = []
setCodeCount = 0 forgeCardCount = 0
mtgDataCardCount = 0
hasFetchedSets = False setCodeCount = 0
hasFetchedCardName = False
tmpName = "" hasFetchedSets = False
line = "" hasFetchedCardName = False
prevline = "" tmpName = ""
line = ""
#Parse mtg-data prevline = ""
print("Parsing mtg-data")
with open(pathToMtgData) as mtgdata : #Parse mtg-data
for line in mtgdata : print("Parsing mtg-data")
if not hasFetchedSets : with open(pathToMtgData) as mtgdata :
if line != "\n" : for line in mtgdata :
setCodes.append(line[0:3]) if not hasFetchedSets :
else : if line != "\n" :
hasFetchedSets = True setCodes.append(line[0:3])
if hasFetchedSets : else :
if not hasFetchedCardName : hasFetchedSets = True
tmpName = line if hasFetchedSets :
tmpName = tmpName.rstrip() if not hasFetchedCardName :
tmpName = tmpName.replace("AE", "Ae") tmpName = line
hasFetchedCardName = True tmpName = tmpName.rstrip()
if line == "\n" : tmpName = tmpName.replace("AE", "Ae")
mtgDataCards[tmpName] = prevline.rstrip() hasFetchedCardName = True
hasFetchedCardName = False if line == "\n" :
mtgDataCards[tmpName] = prevline.rstrip()
prevline = line hasFetchedCardName = False
#Parse Forge prevline = line
print("Parsing Forge")
for i in forgeFolderContents : #Parse Forge
if os.path.isfile(sys.path[0] + os.sep + "cardsfolder" + os.sep + i) == True : print("Parsing Forge")
forgeFolderFiles.append(i) for i in forgeFolderContents :
for file in forgeFolderFiles : if os.path.isfile(sys.path[0] + os.sep + "cardsfolder" + os.sep + i) == True :
with open(sys.path[0] + os.sep + "cardsfolder" + os.sep + file) as currentForgeCard : forgeFolderFiles.append(i)
tmpname = currentForgeCard.readline() for file in forgeFolderFiles :
tmpname = tmpname[5:].replace("AE","Ae") with open(sys.path[0] + os.sep + "cardsfolder" + os.sep + file) as currentForgeCard :
tmpname = tmpname.rstrip() tmpname = currentForgeCard.readline()
forgeCards.append(tmpname) tmpname = tmpname[5:].replace("AE","Ae")
tmpname = tmpname.rstrip()
forgeCards.append(tmpname)
#Compare datasets and output results
print("Comparing datasets and outputting results.") #Compare datasets and output results
totalData = {} print("Comparing datasets and outputting results.")
currentMissing = [] totalData = {}
currentImplemented = [] currentMissing = []
total = 0 currentImplemented = []
percentage = 0 total = 0
for currentSet in setCodes : percentage = 0
if currentSet == 'UNH' or currentSet == 'UGL' : continue #skip Unhinged and Unglued since they are only counting basic lands anyway for currentSet in setCodes :
#if currentSet == 'VG1' or currentSet == 'VG2' or currentSet == 'VG3' : continue if currentSet == 'UNH' or currentSet == 'UGL' : continue #skip Unhinged and Unglued since they are only counting basic lands anyway
#if currentSet == 'VG4' or currentSet == 'VGO' or currentSet == 'VG ' : continue #if currentSet == 'VG1' or currentSet == 'VG2' or currentSet == 'VG3' : continue
#if currentSet == 'FVD' or currentSet == 'FVE' or currentSet == 'FVR' : continue #if currentSet == 'VG4' or currentSet == 'VGO' or currentSet == 'VG ' : continue
#if currentSet == 'SDC' or currentSet == 'AST' or currentSet == 'DKM' : continue #if currentSet == 'FVD' or currentSet == 'FVE' or currentSet == 'FVR' : continue
#if currentSet == 'BTD' or currentSet == 'ARC' or currentSet == 'COM' : continue #if currentSet == 'SDC' or currentSet == 'AST' or currentSet == 'DKM' : continue
#if currentSet == 'CHR' or currentSet == 'MED' or currentSet == 'H09' : continue #if currentSet == 'BTD' or currentSet == 'ARC' or currentSet == 'COM' : continue
#if currentSet == 'ME2' or currentSet == 'ME3' or currentSet == 'ME4' : continue #if currentSet == 'CHR' or currentSet == 'MED' or currentSet == 'H09' : continue
#if currentSet == 'ATH' or currentSet == 'HOP' or currentSet == 'BRB' : continue #if currentSet == 'ME2' or currentSet == 'ME3' or currentSet == 'ME4' : continue
#if currentSet == 'EVG' or currentSet == 'GVL' or currentSet == 'JVC' : continue #if currentSet == 'ATH' or currentSet == 'HOP' or currentSet == 'BRB' : continue
for card in mtgDataCards.keys() : #if currentSet == 'EVG' or currentSet == 'GVL' or currentSet == 'JVC' : continue
if mtgDataCards[card].count(currentSet) > 0 : for card in mtgDataCards.keys() :
if card in forgeCards : if mtgDataCards[card].count(currentSet) > 0 :
currentImplemented.append(card) if card in forgeCards :
else : currentImplemented.append(card)
currentMissing.append(card) else :
total = len(currentMissing)+len(currentImplemented) currentMissing.append(card)
percentage = 0 total = len(currentMissing)+len(currentImplemented)
if total > 0 : percentage = 0
percentage = (float(len(currentImplemented))/float(total))*100 if total > 0 :
percentage = (float(len(currentImplemented))/float(total))*100
currentMissing.sort() currentMissing.sort()
currentImplemented.sort() currentImplemented.sort()
with open(sys.path[0] + os.sep + "PerSetTracking Results" + os.sep + "set_" + currentSet + ".txt", "w") as output : with open(sys.path[0] + os.sep + "PerSetTracking Results" + os.sep + "set_" + currentSet + ".txt", "w") as output :
output.write("Implemented (" + str(len(currentImplemented)) + "):\n") output.write("Implemented (" + str(len(currentImplemented)) + "):\n")
for everyImplemented in currentImplemented : for everyImplemented in currentImplemented :
output.write(everyImplemented + '\n') output.write(everyImplemented + '\n')
output.write("\n") output.write("\n")
output.write("Missing (" + str(len(currentMissing)) + "):\n") output.write("Missing (" + str(len(currentMissing)) + "):\n")
for everyMissing in currentMissing : for everyMissing in currentMissing :
output.write(everyMissing + '\n') output.write(everyMissing + '\n')
output.write("\n") output.write("\n")
output.write("Total: " + str(total) + "\n") output.write("Total: " + str(total) + "\n")
output.write("Percentage implemented: " + str(round(percentage,2)) + "%\n") output.write("Percentage implemented: " + str(round(percentage,2)) + "%\n")
totalData[currentSet] = (len(currentImplemented),len(currentMissing),total,percentage) totalData[currentSet] = (len(currentImplemented),len(currentMissing),total,percentage)
del currentMissing[:] del currentMissing[:]
del currentImplemented[:] del currentImplemented[:]
#sort sets by percentage completed #sort sets by percentage completed
totalDataList = sorted(totalData.items(), key=lambda (key,entry): entry[3], reverse=True) totalDataList = sorted(totalData.items(), key=lambda (key,entry): entry[3], reverse=True)
totalPercentage = 0 totalPercentage = 0
totalMissing = 0 totalMissing = 0
totalImplemented = 0 totalImplemented = 0
fullTotal = 0 fullTotal = 0
with open(sys.path[0] + os.sep + "PerSetTracking Results" + os.sep + "CompleteStats.txt", "w") as statsfile: with open(sys.path[0] + os.sep + "PerSetTracking Results" + os.sep + "CompleteStats.txt", "w") as statsfile:
statsfile.write("Set: Implemented (Missing) / Total = Percentage Implemented\n") statsfile.write("Set: Implemented (Missing) / Total = Percentage Implemented\n")
for k,dataKey in totalDataList : for k,dataKey in totalDataList :
totalImplemented += dataKey[0] totalImplemented += dataKey[0]
totalMissing += dataKey[1] totalMissing += dataKey[1]
fullTotal += dataKey[2] fullTotal += dataKey[2]
statsfile.write(k + ": " + str(dataKey[0]) + " (" + str(dataKey[1]) + ") / " + str(dataKey[2]) + " = " + str(round(dataKey[3], 2)) + "%\n") statsfile.write(k + ": " + str(dataKey[0]) + " (" + str(dataKey[1]) + ") / " + str(dataKey[2]) + " = " + str(round(dataKey[3], 2)) + "%\n")
totalPercentage = totalImplemented / fullTotal totalPercentage = totalImplemented / fullTotal
statsfile.write("\n") statsfile.write("\n")
statsfile.write("Total over all sets: " + str(totalImplemented) + " (" + str(totalMissing) + ") / " + str(fullTotal)) statsfile.write("Total over all sets: " + str(totalImplemented) + " (" + str(totalMissing) + ") / " + str(fullTotal))
print "Done!" print "Done!"
print "Press Enter to exit." print "Press Enter to exit."
raw_input("") raw_input("")

0
res/mtg-data.txt Executable file → Normal file
View File

219
res/reprintSetInfo.py Normal file → Executable file
View File

@@ -1,108 +1,111 @@
# This script grabs the list of all cards in a set and clears out the setInfo #!/usr/bin/env python
# After running this script, re-run setInfoScript to fill in the slots
# MAKE SURE THE setAbbr VARIABLE IS UPDATED TO THE SET YOU WANT TO CLEAR OUT # This script grabs the list of all cards in a set and clears out the setInfo
# After running this script, re-run setInfoScript to fill in the slots
from httplib import HTTP # MAKE SURE THE setAbbr VARIABLE IS UPDATED TO THE SET YOU WANT TO CLEAR OUT
from urlparse import urlparse
from urllib import urlopen from httplib import HTTP
import os from urlparse import urlparse
from urllib import urlopen
class SetInfo: import sys
def __init__(self, set, rarity, image): import os
self.set = set
self.rarity = rarity class SetInfo:
self.image = image def __init__(self, set, rarity, image):
self.set = set
class Card: self.rarity = rarity
def __init__(self, name, cleanName): self.image = image
self.name = name
self.cleanName = cleanName class Card:
self.hasSet = False def __init__(self, name, cleanName):
self.sets = {} self.name = name
self.cleanName = cleanName
def clean(name): self.hasSet = False
return name.replace(' ','_').replace('\'','').replace('-','_').replace('"','').replace(',','').lower() self.sets = {}
def getCardsInSet(): def clean(name):
html = urlopen('http://magiccards.info/query?q=e:'+setAbbr+'&v=olist').read() return name.replace(' ','_').replace('\'','').replace('-','_').replace('"','').replace(',','').lower()
start = html.find('<th><b>Card name</b></th>') def getCardsInSet():
end = html.find('</table>', start) html = urlopen('http://magiccards.info/query?q=e:'+setAbbr+'&v=olist').read()
block = html[start:end]
start = html.find('<th><b>Card name</b></th>')
while True: end = html.find('</table>', start)
nameIndex = block.find('.html">') block = html[start:end]
if nameIndex == -1: while True:
break nameIndex = block.find('.html">')
nameEnd = block.find('<',nameIndex) if nameIndex == -1:
break
name = block[nameIndex+7:nameEnd]
nameEnd = block.find('<',nameIndex)
# Add name to array
nameList.append(clean(name)+'.txt') name = block[nameIndex+7:nameEnd]
block = block[nameEnd:] # Add name to array
nameList.append(clean(name)+'.txt')
return
block = block[nameEnd:]
folder = "cardsfolder"
err = open('reprintSetInfo.log','w') return
# THIS NEEDS TO BE UPDATED TO THE SET YOU WANT TO UPDATE folder = "cardsfolder"
# SOME ARE THREE LETTER ABBR. BUT SOME ARE JUST TWO. CHECK BEFORE YOU RUN! err = open('reprintSetInfo.log','w')
setAbbr = 'mbs'
# THIS NEEDS TO BE UPDATED TO THE SET YOU WANT TO UPDATE
cardDict = {} # SOME ARE THREE LETTER ABBR. BUT SOME ARE JUST TWO. CHECK BEFORE YOU RUN!
setStr = 'SetInfo:' print "Using Set: " + sys.argv[1]
nameList = [] setAbbr = sys.argv[1]
getCardsInSet()
cardDict = {}
for fileName in nameList: setStr = 'SetInfo:'
# if file doesn't exist continue nameList = []
filePath = os.path.join(folder, fileName) getCardsInSet()
print filePath for fileName in nameList:
# if file doesn't exist continue
if os.path.isfile(filePath) == False: filePath = os.path.join(folder, fileName)
continue print filePath
file = open(filePath) if os.path.isfile(filePath) == False:
cleanName = fileName.replace('.txt', '') continue
line = file.readline().strip() file = open(filePath)
# Handle name and creation cleanName = fileName.replace('.txt', '')
name = line.replace('Name:','')
line = file.readline().strip()
card = Card(name, cleanName) # Handle name and creation
cardDict[cleanName] = card name = line.replace('Name:','')
card.lines = line + '\n'
card = Card(name, cleanName)
# Start parsing the rest of the data file cardDict[cleanName] = card
line = file.readline().strip() card.lines = line + '\n'
while line != 'End': # Start parsing the rest of the data file
# Skip empty lines line = file.readline().strip()
if line == '':
line = file.readline().strip() while line != 'End':
continue # Skip empty lines
if line == '':
# We really shouldn line = file.readline().strip()
if line == 'End': continue
break
# We really shouldn
# Skip SetInfo lines if line == 'End':
if line.find(setStr) == -1: break
card.lines += line +'\n'
# Skip SetInfo lines
line = file.readline().strip() if line.find(setStr) == -1:
card.lines += line +'\n'
file = open(os.path.join(folder, fileName), 'w')
file.write(card.lines) line = file.readline().strip()
file.write('End') file = open(os.path.join(folder, fileName), 'w')
file.close() file.write(card.lines)
err.write(card.name + '... Updated\n')
file.write('End')
err.close() file.close()
err.write(card.name + '... Updated\n')
err.close()

516
res/setInfoScript.py Normal file → Executable file
View File

@@ -1,257 +1,259 @@
# This python script is designed to handle the following: individual cards located in /res/cardsfolder #!/usr/bin/env python
# Insert of SetInfo data into data files from magiccards.info
# This python script is designed to handle the following: individual cards located in /res/cardsfolder
from httplib import HTTP # Insert of SetInfo data into data files from magiccards.info
from urlparse import urlparse
from urllib import urlopen from httplib import HTTP
import os from urlparse import urlparse
from urllib import urlopen
def getURL(url): import os
return urlopen(url).read()
def getURL(url):
class SetInfo: return urlopen(url).read()
def __init__(self, set, rarity, image):
self.set = set class SetInfo:
self.rarity = rarity def __init__(self, set, rarity, image):
self.image = image self.set = set
self.rarity = rarity
class Card: self.image = image
def __init__(self, name, cleanName):
self.name = name class Card:
self.cleanName = cleanName def __init__(self, name, cleanName):
self.hasSet = False self.name = name
self.sets = {} self.cleanName = cleanName
self.hasSet = False
def initSets(): self.sets = {}
# Base Sets
allSets['Limited Edition Alpha'] = 'LEA' def initSets():
allSets['Limited Edition Beta'] = 'LEB' # Base Sets
allSets['Unlimited Edition'] = '2ED' allSets['Limited Edition Alpha'] = 'LEA'
allSets['Revised Edition'] = '3ED' allSets['Limited Edition Beta'] = 'LEB'
allSets['Fourth Edition'] = '4ED' allSets['Unlimited Edition'] = '2ED'
allSets['Fifth Edition'] = '5ED' allSets['Revised Edition'] = '3ED'
allSets['Classic Sixth Edition'] = '6ED' allSets['Fourth Edition'] = '4ED'
allSets['Seventh Edition'] = '7ED' allSets['Fifth Edition'] = '5ED'
allSets['Eighth Edition'] = '8ED' allSets['Classic Sixth Edition'] = '6ED'
allSets['Ninth Edition'] = '9ED' allSets['Seventh Edition'] = '7ED'
allSets['Tenth Edition'] = '10E' allSets['Eighth Edition'] = '8ED'
allSets['Magic 2010'] = 'M10' allSets['Ninth Edition'] = '9ED'
allSets['Magic 2011'] = 'M11' allSets['Tenth Edition'] = '10E'
#allSets['Magic 2012'] = 'M12' allSets['Magic 2010'] = 'M10'
allSets['Magic 2011'] = 'M11'
# Portal #allSets['Magic 2012'] = 'M12'
allSets['Portal'] = 'POR'
allSets['Portal Second Age'] = 'PO2' # Portal
allSets['Portal Three Kingdoms'] = 'PTK' allSets['Portal'] = 'POR'
allSets['Portal Second Age'] = 'PO2'
# Starter allSets['Portal Three Kingdoms'] = 'PTK'
allSets['Starter 1999'] = 'S99'
allSets['Starter 2000'] = 'S00' # Starter
allSets['Starter 1999'] = 'S99'
# Early Sets allSets['Starter 2000'] = 'S00'
allSets['Arabian Nights'] = 'ARN'
allSets['Antiquities'] = 'ATQ' # Early Sets
allSets['Legends'] = 'LEG' allSets['Arabian Nights'] = 'ARN'
allSets['The Dark'] = 'DRK' allSets['Antiquities'] = 'ATQ'
allSets['Fallen Empires'] = 'FEM' allSets['Legends'] = 'LEG'
allSets['Homelands'] = 'HML' allSets['The Dark'] = 'DRK'
allSets['Fallen Empires'] = 'FEM'
# Ice Age allSets['Homelands'] = 'HML'
allSets['Ice Age'] = 'ICE'
allSets['Alliances'] = 'ALL' # Ice Age
allSets['Coldsnap'] = 'CSP' allSets['Ice Age'] = 'ICE'
allSets['Alliances'] = 'ALL'
# Mirage allSets['Coldsnap'] = 'CSP'
allSets['Mirage'] = 'MIR'
allSets['Visions'] = 'VIS' # Mirage
allSets['Weatherlight'] = 'WTH' allSets['Mirage'] = 'MIR'
allSets['Visions'] = 'VIS'
# Rath Cycle allSets['Weatherlight'] = 'WTH'
allSets['Tempest'] = 'TMP'
allSets['Stronghold'] = 'STH' # Rath Cycle
allSets['Exodus'] = 'EXO' allSets['Tempest'] = 'TMP'
allSets['Stronghold'] = 'STH'
# Artifacts Cycle allSets['Exodus'] = 'EXO'
allSets['Urza\'s Saga'] = 'USG'
allSets['Urza\'s Legacy'] = 'ULG' # Artifacts Cycle
allSets['Urza\'s Destiny'] = 'UDS' allSets['Urza\'s Saga'] = 'USG'
allSets['Urza\'s Legacy'] = 'ULG'
# Masques allSets['Urza\'s Destiny'] = 'UDS'
allSets['Mercadian Masques'] = 'MMQ'
allSets['Nemesis'] = 'NMS' # Masques
allSets['Prophecy'] = 'PCY' allSets['Mercadian Masques'] = 'MMQ'
allSets['Nemesis'] = 'NMS'
# Invasion allSets['Prophecy'] = 'PCY'
allSets['Invasion'] = 'INV'
allSets['Planeshift'] = 'PLS' # Invasion
allSets['Apocalypse'] = 'APC' allSets['Invasion'] = 'INV'
allSets['Planeshift'] = 'PLS'
# Odyssey allSets['Apocalypse'] = 'APC'
allSets['Odyssey'] = 'ODY'
allSets['Torment'] = 'TOR' # Odyssey
allSets['Judgment'] = 'JUD' allSets['Odyssey'] = 'ODY'
allSets['Torment'] = 'TOR'
# Onslaught allSets['Judgment'] = 'JUD'
allSets['Onslaught'] = 'ONS'
allSets['Legions'] = 'LGN' # Onslaught
allSets['Scourge'] = 'SCG' allSets['Onslaught'] = 'ONS'
allSets['Legions'] = 'LGN'
# Mirrodin allSets['Scourge'] = 'SCG'
allSets['Mirrodin'] = 'MRD'
allSets['Darksteel'] = 'DST' # Mirrodin
allSets['Fifth Dawn'] = '5DN' allSets['Mirrodin'] = 'MRD'
allSets['Darksteel'] = 'DST'
# Kamigawa allSets['Fifth Dawn'] = '5DN'
allSets['Champions of Kamigawa'] = 'CHK'
allSets['Betrayers of Kamigawa'] = 'BOK' # Kamigawa
allSets['Saviors of Kamigawa'] = 'SOK' allSets['Champions of Kamigawa'] = 'CHK'
allSets['Betrayers of Kamigawa'] = 'BOK'
# Ravnica allSets['Saviors of Kamigawa'] = 'SOK'
allSets['Ravnica: City of Guilds'] = 'RAV'
allSets['Guildpact'] = 'GPT' # Ravnica
allSets['Dissension'] = 'DIS' allSets['Ravnica: City of Guilds'] = 'RAV'
allSets['Guildpact'] = 'GPT'
# Time Spiral allSets['Dissension'] = 'DIS'
allSets['Time Spiral'] = 'TSP'
allSets['Time Spiral "Timeshifted"'] = 'TSB' # Time Spiral
allSets['Planar Chaos'] = 'PLC' allSets['Time Spiral'] = 'TSP'
allSets['Future Sight'] = 'FUT' allSets['Time Spiral "Timeshifted"'] = 'TSB'
allSets['Planar Chaos'] = 'PLC'
# Lorwyn allSets['Future Sight'] = 'FUT'
allSets['Lorwyn'] = 'LRW'
allSets['Morningtide'] = 'MOR' # Lorwyn
allSets['Lorwyn'] = 'LRW'
# Shadowmoor allSets['Morningtide'] = 'MOR'
allSets['Shadowmoor'] = 'SHM'
allSets['Eventide'] = 'EVE' # Shadowmoor
allSets['Shadowmoor'] = 'SHM'
# Alara allSets['Eventide'] = 'EVE'
allSets['Shards of Alara'] = 'ALA'
allSets['Conflux'] = 'CFX' # Alara
allSets['Alara Reborn'] = 'ARB' allSets['Shards of Alara'] = 'ALA'
allSets['Conflux'] = 'CFX'
# Zendikar allSets['Alara Reborn'] = 'ARB'
allSets['Zendikar'] = 'ZEN'
allSets['Worldwake'] = 'WWK' # Zendikar
allSets['Rise of the Eldrazi'] = 'ROE' allSets['Zendikar'] = 'ZEN'
allSets['Worldwake'] = 'WWK'
# Scars of Mirrodin allSets['Rise of the Eldrazi'] = 'ROE'
allSets['Scars of Mirrodin'] = 'SOM'
allSets['Mirrodin Besieged'] = 'MBS' # Scars of Mirrodin
allSets['New Phyrexia'] = 'NPH' allSets['Scars of Mirrodin'] = 'SOM'
allSets['Mirrodin Besieged'] = 'MBS'
def addSets(card): allSets['New Phyrexia'] = 'NPH'
html = getURL('http://magiccards.info/query?q=!'+card.name)
start = html.find('<br><u><b>Editions:</b></u><br>') def addSets(card):
end = html.find('<br><u><b>Languages:</b></u><br>', start) html = getURL('http://magiccards.info/query?q=!'+card.name)
block = html[start:end] start = html.find('<br><u><b>Editions:</b></u><br>')
end = html.find('<br><u><b>Languages:</b></u><br>', start)
print card.name block = html[start:end]
for edition in allSets.keys(): print card.name
edIndex = block.find('>'+edition+'<') # Portal/Mirrodin issue
for edition in allSets.keys():
if edIndex == -1: edIndex = block.find('>'+edition+'<') # Portal/Mirrodin issue
edIndex = block.find('>'+edition+' (') # Single set issue
if edIndex == -1: if edIndex == -1:
continue edIndex = block.find('>'+edition+' (') # Single set issue
if edIndex == -1:
# Scrape rarity continue
rarityIndex = block.find('(',edIndex)
rarity = block[rarityIndex+1:block.find(')',rarityIndex)] # Scrape rarity
raritySpace = rarity.find(' ') rarityIndex = block.find('(',edIndex)
if raritySpace != -1: rarity = block[rarityIndex+1:block.find(')',rarityIndex)]
rarity = rarity[0:raritySpace] # For older cards raritySpace = rarity.find(' ')
if raritySpace != -1:
# What to do with TimeShifted cards? rarity = rarity[0:raritySpace] # For older cards
if rarity == 'Special' and edition != 'Time Spiral "Timeshifted"':
continue # What to do with TimeShifted cards?
if rarity == 'Special' and edition != 'Time Spiral "Timeshifted"':
# Get setAbbreviation and setNumber continue
dataIndex = block.rfind('"/',0,edIndex)
data = block[dataIndex+2:edIndex-1] # 1 instead of 2 because of Portal/Mirrodin Issue # Get setAbbreviation and setNumber
dataIndex = block.rfind('"/',0,edIndex)
splitData = data.split('/') data = block[dataIndex+2:edIndex-1] # 1 instead of 2 because of Portal/Mirrodin Issue
setAbbr = splitData[0]
setNum = splitData[2].replace('.html', '') splitData = data.split('/')
setAbbr = splitData[0]
if len(setNum) > 4: setNum = splitData[2].replace('.html', '')
# Setnum not available here for most recent set. Switch to the .jpg used on page
jpgIndex = html.find('.jpg') if len(setNum) > 4:
data = html[html.rfind('scans/en/', 0, jpgIndex):jpgIndex] # Setnum not available here for most recent set. Switch to the .jpg used on page
jpgIndex = html.find('.jpg')
# data = scans/en/[set]/[num] data = html[html.rfind('scans/en/', 0, jpgIndex):jpgIndex]
splitData = data.split('/')
setAbbr = splitData[2] # data = scans/en/[set]/[num]
setNum = splitData[3] splitData = data.split('/')
setAbbr = splitData[2]
image = 'http://magiccards.info/scans/en/' + setAbbr + '/' + setNum + '.jpg' setNum = splitData[3]
card.sets[allSets[edition]] = SetInfo(allSets[edition], rarity, image) image = 'http://magiccards.info/scans/en/' + setAbbr + '/' + setNum + '.jpg'
return card.sets[allSets[edition]] = SetInfo(allSets[edition], rarity, image)
return
#get master card list and drop into a dictionary
folder = "cardsfolder"
err = open('setInfoScript.log','w') #get master card list and drop into a dictionary
allSets = {} folder = "cardsfolder"
initSets() err = open('setInfoScript.log','w')
cardDict = {} allSets = {}
setStr = 'SetInfo:' initSets()
cardDict = {}
for fileName in os.listdir(folder): setStr = 'SetInfo:'
if fileName.startswith('.'):
continue for fileName in os.listdir(folder):
if fileName.startswith('.'):
# parse cardsfolder for Card Lines and Rarity/Picture SVars. Filling in any gaps continue
file = open(folder + os.sep + fileName)
cleanName = fileName.replace('.txt', '') # parse cardsfolder for Card Lines and Rarity/Picture SVars. Filling in any gaps
file = open(folder + os.sep + fileName)
line = file.readline().strip() cleanName = fileName.replace('.txt', '')
# Handle name and creation
name = line.replace('Name:','') line = file.readline().strip()
# Handle name and creation
card = Card(name.replace(' ','+'), cleanName) #This makes it work on Mac OS X. Will test Windows and FreeBSD when I can. name = line.replace('Name:','')
cardDict[cleanName] = card
card.lines = line + '\n' card = Card(name.replace(' ','+'), cleanName) #This makes it work on Mac OS X. Will test Windows and FreeBSD when I can.
cardDict[cleanName] = card
# Start parsing the rest of the data file card.lines = line + '\n'
line = file.readline().strip()
# Start parsing the rest of the data file
while line != 'End': line = file.readline().strip()
# Skip empty lines
if line == '': while line != 'End':
line = file.readline().strip() # Skip empty lines
continue if line == '':
line = file.readline().strip()
# We really shouldn't continue
if line == 'End':
break # We really shouldn't
if line == 'End':
if line.find(setStr) != -1: break
info = line.replace('SetInfo:','')
parts = info.split('|') if line.find(setStr) != -1:
info = line.replace('SetInfo:','')
card.hasSet = True parts = info.split('|')
card.sets[parts[0]] = SetInfo(parts[0], parts[1], parts[2])
else: card.hasSet = True
card.lines += line +'\n' card.sets[parts[0]] = SetInfo(parts[0], parts[1], parts[2])
else:
line = file.readline().strip() card.lines += line +'\n'
if not card.hasSet: line = file.readline().strip()
addSets(card)
card.hasSet = True if not card.hasSet:
addSets(card)
file = open(folder + os.sep + fileName, 'w') card.hasSet = True
file.write(card.lines)
if card.hasSet: file = open(folder + os.sep + fileName, 'w')
for s in card.sets.values(): file.write(card.lines)
file.write('SetInfo:'+ s.set + '|' + s.rarity + '|' + s.image + '\n') if card.hasSet:
for s in card.sets.values():
file.write('End') file.write('SetInfo:'+ s.set + '|' + s.rarity + '|' + s.image + '\n')
file.close()
err.write(card.name + '... Updated\n') file.write('End')
file.close()
err.close() err.write(card.name + '... Updated\n')
err.close()