- Improving some tools

This commit is contained in:
Sol
2016-09-06 13:14:28 +00:00
parent 33312f130a
commit ef49aaed19
2 changed files with 31 additions and 13 deletions

View File

@@ -7,13 +7,16 @@ start = 0
incr = 15 incr = 15
# Update these variables, or even better convert to Arguments # 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 = '' txt = ''
folder = 'SOI' folder = 'KLD'
cards = 0 cards = 0
def normalize_name(name): 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 condition = True
try: try:
@@ -33,14 +36,18 @@ while condition:
if not e.text.startswith('Name:'): if not e.text.startswith('Name:'):
continue continue
script = lxml.html.tostring(e)[6:-7].replace('</a>', '').replace('&lt;','<').replace('&gt;', '>') script = lxml.html.tostring(e)[6:-7].replace('</a>', '')
#allCards.write(script.replace('<br>', '\n'))
#allCards.write('\n\n')
while True: while True:
idx = script.find('<a ') idx = script.find('<a ')
if idx == -1: if idx == -1:
break break
backIdx = script.find('>', idx) backIdx = script.find('>', idx)
#print script[idx:backIdx]
script = script[0:idx] + script[backIdx+1:] script = script[0:idx] + script[backIdx+1:]
#script = script.replace('&lt;','<').replace('&gt;', '>')
lines = script.split('<br>') lines = script.split('<br>')
name = '' name = ''
@@ -64,14 +71,18 @@ while condition:
path = os.path.join(folder, '%s%s.txt' % (name, i)) path = os.path.join(folder, '%s%s.txt' % (name, i))
i += 1 i += 1
try:
with open(path, 'w') as f: with open(path, 'w') as f:
for line in lines: for line in lines:
f.write("%s\n" % line) f.write("%s\n" % line)
except:
print path, " Failed..."
continue
cards += 1 cards += 1
start += incr start += incr
print ("About to loop...") print ("About to loop... %s" % start)
raw_input("Press Enter to continue...") raw_input("Press Enter to continue...")

View File

@@ -20,18 +20,25 @@ r = requests.get('http://mtgjson.com/json/%s.json' % result.setcode)
d = r.json() d = r.json()
cards = d['cards'] cards = d['cards']
f = open('%s.txt' % result.name, 'w') f = open('%s.txt' % d['name'], 'w')
f.write('[metadata]\n') f.write('[metadata]\n')
f.write('Code=%s\n' % result.setcode) f.write('Code=%s\n' % result.setcode)
f.write('Date=2015-XX-XX\n') f.write('Date=%s\n' % d['releaseDate'])
f.write('Name=%s\n' % result.name) f.write('Name=%s\n' % d['name'])
f.write('Code2=%s\n' % result.setcode) 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') f.write('[cards]\n')
for c in cards: for c in cards:
l = []
l.append(c['number'])
rarity = c['rarity'][0] rarity = c['rarity'][0]
if rarity == 'B': if rarity == 'B':
rarity = 'L' 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))