mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
- Improving some tools
This commit is contained in:
@@ -7,13 +7,16 @@ start = 0
|
||||
incr = 15
|
||||
|
||||
# Update these variables, or even better convert to Arguments
|
||||
url ='http://www.slightlymagic.net/forum/viewtopic.php?f=52&t=18242&start=%s'
|
||||
url ='http://www.slightlymagic.net/forum/viewtopic.php?f=52&t=19036&start=%s'
|
||||
txt = ''
|
||||
folder = 'SOI'
|
||||
folder = 'KLD'
|
||||
cards = 0
|
||||
|
||||
def normalize_name(name):
|
||||
return name.lower().replace(' ', '_').replace("'", '').replace(u'\xc6', 'AE')
|
||||
return name.lower().replace(' ', '_').replace("'", '').replace(',', '').replace(u'\xc6', 'AE')
|
||||
|
||||
|
||||
#allCards = file(os.path.join(folder, 'allcards.txt'), 'w')
|
||||
|
||||
condition = True
|
||||
try:
|
||||
@@ -33,14 +36,18 @@ while condition:
|
||||
if not e.text.startswith('Name:'):
|
||||
continue
|
||||
|
||||
script = lxml.html.tostring(e)[6:-7].replace('</a>', '').replace('<','<').replace('>', '>')
|
||||
script = lxml.html.tostring(e)[6:-7].replace('</a>', '')
|
||||
#allCards.write(script.replace('<br>', '\n'))
|
||||
#allCards.write('\n\n')
|
||||
while True:
|
||||
idx = script.find('<a ')
|
||||
if idx == -1:
|
||||
break
|
||||
backIdx = script.find('>', idx)
|
||||
#print script[idx:backIdx]
|
||||
script = script[0:idx] + script[backIdx+1:]
|
||||
|
||||
#script = script.replace('<','<').replace('>', '>')
|
||||
lines = script.split('<br>')
|
||||
|
||||
name = ''
|
||||
@@ -64,14 +71,18 @@ while condition:
|
||||
path = os.path.join(folder, '%s%s.txt' % (name, i))
|
||||
i += 1
|
||||
|
||||
try:
|
||||
with open(path, 'w') as f:
|
||||
for line in lines:
|
||||
f.write("%s\n" % line)
|
||||
except:
|
||||
print path, " Failed..."
|
||||
continue
|
||||
|
||||
cards += 1
|
||||
|
||||
start += incr
|
||||
print ("About to loop...")
|
||||
print ("About to loop... %s" % start)
|
||||
raw_input("Press Enter to continue...")
|
||||
|
||||
|
||||
|
||||
@@ -20,18 +20,25 @@ r = requests.get('http://mtgjson.com/json/%s.json' % result.setcode)
|
||||
d = r.json()
|
||||
cards = d['cards']
|
||||
|
||||
f = open('%s.txt' % result.name, 'w')
|
||||
f = open('%s.txt' % d['name'], 'w')
|
||||
|
||||
f.write('[metadata]\n')
|
||||
f.write('Code=%s\n' % result.setcode)
|
||||
f.write('Date=2015-XX-XX\n')
|
||||
f.write('Name=%s\n' % result.name)
|
||||
f.write('Date=%s\n' % d['releaseDate'])
|
||||
f.write('Name=%s\n' % d['name'])
|
||||
f.write('Code2=%s\n' % result.setcode)
|
||||
f.write('Type=%s\n\n' % result.settype)
|
||||
f.write('MciCode=%s\n' % result.setcode.lower())
|
||||
f.write('Type=%s\n\n' % d['type'])
|
||||
f.write('[cards]\n')
|
||||
|
||||
for c in cards:
|
||||
l = []
|
||||
l.append(c['number'])
|
||||
|
||||
rarity = c['rarity'][0]
|
||||
if rarity == 'B':
|
||||
rarity = 'L'
|
||||
f.write(rarity + ' ' + c['name'].replace(u'\xc6', 'AE') + '\n')
|
||||
l.append(rarity)
|
||||
l.append(c['name'].replace(u'\xc6', 'AE'))
|
||||
l.append('\n')
|
||||
f.write(' '.join(l))
|
||||
Reference in New Issue
Block a user