mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
- Deleting migrated Python Script, which was for old cards.txt formatting
- Adding new setInfo Python Script for Rob's Set/Image work
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -5417,7 +5417,6 @@ res/lib/napkinlaf-1.2.jar -text svneol=unset#unset
|
|||||||
res/lib/nimrodlf.jar -text svneol=unset#unset
|
res/lib/nimrodlf.jar -text svneol=unset#unset
|
||||||
res/lib/substance.jar -text svneol=unset#unset
|
res/lib/substance.jar -text svneol=unset#unset
|
||||||
res/main.properties svneol=native#text/plain
|
res/main.properties svneol=native#text/plain
|
||||||
res/migratedCardsScript.py -text svneol=native#text/x-python
|
|
||||||
res/pics/BookIcon.png -text svneol=unset#image/png
|
res/pics/BookIcon.png -text svneol=unset#image/png
|
||||||
res/pics/BoxIcon.png -text svneol=unset#image/png
|
res/pics/BoxIcon.png -text svneol=unset#image/png
|
||||||
res/pics/GoldIcon.png -text svneol=unset#image/png
|
res/pics/GoldIcon.png -text svneol=unset#image/png
|
||||||
@@ -5719,6 +5718,7 @@ res/quest/themes/Vigilance[!!-~]Meekstone[!!-~]W.thm -text
|
|||||||
res/quest/themes/White.thm -text
|
res/quest/themes/White.thm -text
|
||||||
res/quest/uncommon.txt -text svneol=native#text/plain
|
res/quest/uncommon.txt -text svneol=native#text/plain
|
||||||
res/rare.txt -text svneol=native#text/plain
|
res/rare.txt -text svneol=native#text/plain
|
||||||
|
res/setInfoScript.py -text svneol=native#text/x-python
|
||||||
res/sound/tap.mp3 -text svneol=unset#audio/mpeg
|
res/sound/tap.mp3 -text svneol=unset#audio/mpeg
|
||||||
res/uncommon.txt -text svneol=native#text/plain
|
res/uncommon.txt -text svneol=native#text/plain
|
||||||
src/Deck.java svneol=native#text/plain
|
src/Deck.java svneol=native#text/plain
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
from httplib import HTTP
|
|
||||||
from urlparse import urlparse
|
|
||||||
from urllib import urlopen
|
|
||||||
|
|
||||||
def clean(name):
|
|
||||||
return name.lower().replace('-',' ').replace(',','').replace('_', ' ').replace('\'', '').replace('\"', '').replace('.', '').strip()
|
|
||||||
|
|
||||||
def checkURL(url):
|
|
||||||
p = urlparse(url)
|
|
||||||
h = HTTP(p[1])
|
|
||||||
h.putrequest('HEAD', p[2])
|
|
||||||
h.endheaders()
|
|
||||||
if h.getreply()[0] == 200: return 1
|
|
||||||
else: return 0
|
|
||||||
|
|
||||||
def getURL(url):
|
|
||||||
return urlopen(url).read()
|
|
||||||
|
|
||||||
def getSVarString(line, str):
|
|
||||||
start = line.find(str) + len(str) + 1
|
|
||||||
return line[start:].strip()
|
|
||||||
|
|
||||||
def getRarity(name):
|
|
||||||
html = getURL('http://magiccards.info/query?q=!'+name)
|
|
||||||
# magiccards.info uses (<rarity>) on the page for rarity.
|
|
||||||
# since older editions had funky things like c2, and u1, only use open parenthesis for this search
|
|
||||||
landCount = html.count("(Land")
|
|
||||||
commonCount = html.count("(Common")
|
|
||||||
uncommonCount = html.count("(Uncommon")
|
|
||||||
rareCount = html.count("(Rare")
|
|
||||||
mythicCount = html.count("(Mythic Rare)")
|
|
||||||
if (landCount > 0):
|
|
||||||
return 'Land'
|
|
||||||
elif (commonCount + uncommonCount + rareCount + mythicCount == 0):
|
|
||||||
err.write("Bad magiccards.info Query: " + name + '\n')
|
|
||||||
return ''
|
|
||||||
elif (commonCount >= uncommonCount and commonCount >= rareCount and commonCount >= mythicCount):
|
|
||||||
return 'Common'
|
|
||||||
elif (commonCount < uncommonCount and uncommonCount >= rareCount and uncommonCount >= mythicCount):
|
|
||||||
return 'Uncommon'
|
|
||||||
elif (rareCount >= mythicCount):
|
|
||||||
return 'Rare'
|
|
||||||
else:
|
|
||||||
return 'Mythic'
|
|
||||||
|
|
||||||
def getPicture(name):
|
|
||||||
urlName = name.replace(' ', '_')
|
|
||||||
picUrl ='http://www.wizards.com/global/images/magic/general/' + urlName + '.jpg'
|
|
||||||
if not checkURL(picUrl):
|
|
||||||
err.write("Bad Picture URL " + name + '\n')
|
|
||||||
return ''
|
|
||||||
return picUrl
|
|
||||||
|
|
||||||
class Card:
|
|
||||||
def __init__(self, name):
|
|
||||||
self.name = name
|
|
||||||
self.cleanName = clean(name)
|
|
||||||
self.hasPicture = False
|
|
||||||
self.picURL = ''
|
|
||||||
self.hasRarity = False
|
|
||||||
self.rarity = ''
|
|
||||||
self.lines = ''
|
|
||||||
|
|
||||||
#get master card list and drop into a dictionary
|
|
||||||
file = open('cards.txt')
|
|
||||||
err = open('cardsScript.log','w')
|
|
||||||
line = file.readline().strip()
|
|
||||||
cardDict = {}
|
|
||||||
rarityStr = 'SVar:Rarity'
|
|
||||||
pictureStr = 'SVar:Picture'
|
|
||||||
|
|
||||||
# parse cards.txt for Card Lines and Rarity/Picture SVars. Filling in any gaps
|
|
||||||
while line != 'End':
|
|
||||||
temp = Card(line)
|
|
||||||
cardDict[temp.cleanName] = temp
|
|
||||||
skip = file.readline()
|
|
||||||
while skip.strip() != '':
|
|
||||||
if skip.find(rarityStr) != -1:
|
|
||||||
temp.hasRarity = True
|
|
||||||
temp.rarity = getSVarString(skip, rarityStr)
|
|
||||||
elif skip.find(pictureStr) != -1:
|
|
||||||
temp.hasPicture = True
|
|
||||||
temp.picURL = getSVarString(skip, pictureStr)
|
|
||||||
else:
|
|
||||||
temp.lines += skip
|
|
||||||
skip = file.readline()
|
|
||||||
|
|
||||||
if not temp.hasRarity:
|
|
||||||
rarity = getRarity(temp.name)
|
|
||||||
if not rarity == '':
|
|
||||||
temp.hasRarity = True
|
|
||||||
temp.rarity = rarity
|
|
||||||
|
|
||||||
if not temp.hasPicture:
|
|
||||||
pic = getPicture(temp.cleanName)
|
|
||||||
if not pic == '':
|
|
||||||
temp.hasPicture = True
|
|
||||||
temp.picURL = pic
|
|
||||||
|
|
||||||
line = file.readline().strip()
|
|
||||||
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
file = open('cards.txt', 'w')
|
|
||||||
|
|
||||||
for c in sorted(cardDict):
|
|
||||||
card = cardDict[c]
|
|
||||||
file.write(card.name+'\n')
|
|
||||||
file.write(card.lines)
|
|
||||||
if card.hasRarity:
|
|
||||||
file.write('SVar:Rarity:'+card.rarity + '\n')
|
|
||||||
if card.hasPicture:
|
|
||||||
file.write('SVar:Picture:'+card.picURL + '\n')
|
|
||||||
file.write('\n')
|
|
||||||
|
|
||||||
file.write('End')
|
|
||||||
file.close()
|
|
||||||
err.close()
|
|
||||||
244
res/setInfoScript.py
Normal file
244
res/setInfoScript.py
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
# This python script is designed to handle the following: individual cards located in /res/cardsfolder
|
||||||
|
# Insert of SetInfo data into data files from magiccards.info
|
||||||
|
|
||||||
|
from httplib import HTTP
|
||||||
|
from urlparse import urlparse
|
||||||
|
from urllib import urlopen
|
||||||
|
import os
|
||||||
|
|
||||||
|
def getURL(url):
|
||||||
|
return urlopen(url).read()
|
||||||
|
|
||||||
|
class SetInfo:
|
||||||
|
def __init__(self, set, rarity, image):
|
||||||
|
self.set = set
|
||||||
|
self.rarity = rarity
|
||||||
|
self.image = image
|
||||||
|
|
||||||
|
class Card:
|
||||||
|
def __init__(self, name, cleanName):
|
||||||
|
self.name = name
|
||||||
|
self.cleanName = cleanName
|
||||||
|
self.hasSet = False
|
||||||
|
self.sets = {}
|
||||||
|
|
||||||
|
def initSets():
|
||||||
|
# Base Sets
|
||||||
|
allSets['Limited Edition Beta'] = 'LEB'
|
||||||
|
allSets['Unlimited Edition'] = '2ED'
|
||||||
|
allSets['Revised Edition'] = '3ED'
|
||||||
|
allSets['Fourth Edition'] = '4ED'
|
||||||
|
allSets['Fifth Edition'] = '5ED'
|
||||||
|
allSets['Classic Sixth Edition'] = '6ED'
|
||||||
|
allSets['Seventh Edition'] = '7ED'
|
||||||
|
allSets['Eighth Edition'] = '8ED'
|
||||||
|
allSets['Ninth Edition'] = '9ED'
|
||||||
|
allSets['Tenth Edition'] = '10E'
|
||||||
|
allSets['Magic 2010'] = 'M10'
|
||||||
|
allSets['Magic 2011'] = 'M11'
|
||||||
|
|
||||||
|
# Portal
|
||||||
|
allSets['Portal'] = 'POR'
|
||||||
|
allSets['Portal Second Age'] = 'P02'
|
||||||
|
allSets['Portal Three Kingdoms'] = 'PTK'
|
||||||
|
|
||||||
|
# Starter
|
||||||
|
allSets['Starter 1999'] = 'S99'
|
||||||
|
allSets['Starter 2000'] = 'S00'
|
||||||
|
|
||||||
|
# Early Sets
|
||||||
|
allSets['Arabian Nights'] = 'ARN'
|
||||||
|
allSets['Antiquities'] = 'ATQ'
|
||||||
|
allSets['Legends'] = 'LEG'
|
||||||
|
allSets['The Dark'] = 'DRK'
|
||||||
|
allSets['Fallen Empires'] = 'FEM'
|
||||||
|
allSets['Homelands'] = 'HML'
|
||||||
|
|
||||||
|
# Ice Age
|
||||||
|
allSets['Ice Age'] = 'ICE'
|
||||||
|
allSets['Alliances'] = 'ALL'
|
||||||
|
allSets['Coldsnap'] = 'CSP'
|
||||||
|
|
||||||
|
# Mirage
|
||||||
|
allSets['Mirage'] = 'MIR'
|
||||||
|
allSets['Visions'] = 'VIS'
|
||||||
|
allSets['Weatherlight'] = 'WTH'
|
||||||
|
|
||||||
|
# Rath Cycle
|
||||||
|
allSets['Tempest'] = 'TMP'
|
||||||
|
allSets['Stronghold'] = 'STH'
|
||||||
|
allSets['Exodus'] = 'EXO'
|
||||||
|
|
||||||
|
# Artifacts Cycle
|
||||||
|
allSets['Urza\'s Saga'] = 'USG'
|
||||||
|
allSets['Urza\'s Legacy'] = 'ULG'
|
||||||
|
allSets['Urza\'s Destiny'] = 'UDS'
|
||||||
|
|
||||||
|
# Masques
|
||||||
|
allSets['Mercadian Masques'] = 'MMQ'
|
||||||
|
allSets['Nemesis'] = 'NMS'
|
||||||
|
allSets['Prophecy'] = 'PCY'
|
||||||
|
|
||||||
|
# Invasion
|
||||||
|
allSets['Invasion'] = 'INV'
|
||||||
|
allSets['Planeshift'] = 'PLS'
|
||||||
|
allSets['Apocalypse'] = 'APC'
|
||||||
|
|
||||||
|
# Odyssey
|
||||||
|
allSets['Odyssey'] = 'ODY'
|
||||||
|
allSets['Torment'] = 'TOR'
|
||||||
|
allSets['Judgment'] = 'JUD'
|
||||||
|
|
||||||
|
# Onslaught
|
||||||
|
allSets['Onslaught'] = 'ONS'
|
||||||
|
allSets['Legions'] = 'LGN'
|
||||||
|
allSets['Scourge'] = 'SCG'
|
||||||
|
|
||||||
|
# Mirrodin
|
||||||
|
allSets['Mirrodin'] = 'MRD'
|
||||||
|
allSets['Darksteel'] = 'DST'
|
||||||
|
allSets['Fifth Dawn'] = '5DN'
|
||||||
|
|
||||||
|
# Kamigawa
|
||||||
|
allSets['Champions of Kamigawa'] = 'CHK'
|
||||||
|
allSets['Betrayers of Kamigawa'] = 'BOK'
|
||||||
|
allSets['Saviors of Kamigawa'] = 'SOK'
|
||||||
|
|
||||||
|
# Ravnica
|
||||||
|
allSets['Ravnica: City of Guilds'] = 'RAV'
|
||||||
|
allSets['Guildpact'] = 'GPT'
|
||||||
|
allSets['Dissension'] = 'DIS'
|
||||||
|
|
||||||
|
# Time Spiral
|
||||||
|
allSets['Time Spiral'] = 'TSP'
|
||||||
|
allSets['Planar Chaos'] = 'PLC'
|
||||||
|
allSets['Future Sight'] = 'FUT'
|
||||||
|
|
||||||
|
# Lorwyn
|
||||||
|
allSets['Lorwyn'] = 'LRW'
|
||||||
|
allSets['Morningtide'] = 'MOR'
|
||||||
|
|
||||||
|
# Shadowmoor
|
||||||
|
allSets['Shadowmoor'] = 'SHM'
|
||||||
|
allSets['Eventide'] = 'EVE'
|
||||||
|
|
||||||
|
# Alara
|
||||||
|
allSets['Shards of Alara'] = 'ALA'
|
||||||
|
allSets['Conflux'] = 'CON'
|
||||||
|
allSets['Alara Reborn'] = 'ARB'
|
||||||
|
|
||||||
|
# Zendikar
|
||||||
|
allSets['Zendikar'] = 'ZEN'
|
||||||
|
allSets['Worldwake'] = 'WWK'
|
||||||
|
allSets['Rise of the Eldrazi'] = 'ROE'
|
||||||
|
|
||||||
|
# Scars of Mirrodin
|
||||||
|
allSets['Scars of Mirrodin'] = 'SOM'
|
||||||
|
allSets['Mirrodin Beseiged'] = 'MBS'
|
||||||
|
#allSets['Unknown Mirrodin Set']
|
||||||
|
|
||||||
|
def addSets(card):
|
||||||
|
html = getURL('http://magiccards.info/query?q=!'+card.name)
|
||||||
|
start = html.find('<br><u><b>Editions:</b></u><br>')
|
||||||
|
end = html.find('<br><u><b>Languages:</b></u><br>', start)
|
||||||
|
block = html[start:end]
|
||||||
|
|
||||||
|
for edition in allSets.keys():
|
||||||
|
edIndex = block.find(edition)
|
||||||
|
if edIndex == -1:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Scrape rarity
|
||||||
|
rarityIndex = block.find('(',edIndex)
|
||||||
|
rarity = block[rarityIndex+1:block.find(')',rarityIndex)]
|
||||||
|
raritySpace = rarity.find(' ')
|
||||||
|
if raritySpace != -1:
|
||||||
|
rarity = rarity[0:raritySpace] # For older cards
|
||||||
|
|
||||||
|
# What to do with TimeShifted cards?
|
||||||
|
if rarity == 'Special':
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Get setAbbreviation and setNumber
|
||||||
|
dataIndex = block.rfind('"/',0,edIndex)
|
||||||
|
data = block[dataIndex+2:edIndex-2]
|
||||||
|
|
||||||
|
splitData = data.split('/')
|
||||||
|
setAbbr = splitData[0]
|
||||||
|
setNum = splitData[2].replace('.html', '')
|
||||||
|
|
||||||
|
if len(setNum) > 4:
|
||||||
|
# Setnum not available here for most recent set. Switch to the .jpg used on page
|
||||||
|
jpgIndex = html.find('.jpg')
|
||||||
|
splitData = html[html.rfind('en/', 0, jpgIndex):jpgIndex].split('/')
|
||||||
|
|
||||||
|
setAbbr = splitData[1]
|
||||||
|
setNum = splitData[2]
|
||||||
|
|
||||||
|
image = 'http://magiccards.info/scans/en/' + setAbbr + '/' + setNum + '.jpg'
|
||||||
|
|
||||||
|
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')
|
||||||
|
allSets = {}
|
||||||
|
initSets()
|
||||||
|
cardDict = {}
|
||||||
|
setStr = 'SetInfo:'
|
||||||
|
|
||||||
|
for fileName in os.listdir(folder):
|
||||||
|
# parse cardsfolder for Card Lines and Rarity/Picture SVars. Filling in any gaps
|
||||||
|
file = open(folder + '\\' + fileName)
|
||||||
|
cleanName = fileName.replace('.txt', '')
|
||||||
|
|
||||||
|
line = file.readline().strip()
|
||||||
|
# Handle name and creation
|
||||||
|
name = line.replace('Name:','')
|
||||||
|
|
||||||
|
card = Card(name, cleanName)
|
||||||
|
cardDict[cleanName] = card
|
||||||
|
card.lines = line + '\n'
|
||||||
|
|
||||||
|
# Start parsing the rest of the data file
|
||||||
|
line = file.readline().strip()
|
||||||
|
|
||||||
|
while line != 'End':
|
||||||
|
# Skip empty lines
|
||||||
|
if line == '':
|
||||||
|
line = file.readline().strip()
|
||||||
|
continue
|
||||||
|
|
||||||
|
# We really shouldn
|
||||||
|
if line == 'End':
|
||||||
|
break
|
||||||
|
|
||||||
|
if line.find(setStr) != -1:
|
||||||
|
info = line.replace('SetInfo:','')
|
||||||
|
parts = info.split('|')
|
||||||
|
|
||||||
|
card.hasSet = True
|
||||||
|
card.sets[parts[0]] = SetInfo(parts[0], parts[1], parts[2])
|
||||||
|
else:
|
||||||
|
card.lines += line +'\n'
|
||||||
|
|
||||||
|
line = file.readline().strip()
|
||||||
|
|
||||||
|
if not card.hasSet:
|
||||||
|
addSets(card)
|
||||||
|
card.hasSet = True
|
||||||
|
|
||||||
|
file = open(folder + "/" + fileName, 'w')
|
||||||
|
file.write(card.lines)
|
||||||
|
if card.hasSet:
|
||||||
|
for s in card.sets.values():
|
||||||
|
file.write('SetInfo:'+ s.set + '|' + s.rarity + '|' + s.image + '\n')
|
||||||
|
|
||||||
|
file.write('End')
|
||||||
|
file.close()
|
||||||
|
err.write(card.name + '... Updated\n')
|
||||||
|
|
||||||
|
err.close()
|
||||||
Reference in New Issue
Block a user