mirror of
https://github.com/Cockatrice/Magic-Spoiler.git
synced 2026-08-27 20:04:55 -05:00
Pretty spoiler.xml
This commit is contained in:
8
main.py
8
main.py
@@ -65,9 +65,9 @@ def save_errorlog(errorlog):
|
||||
with open('out/errors.json', 'w') as outfile:
|
||||
json.dump(errorlog, outfile, sort_keys=True, indent=2, separators=(',', ': '))
|
||||
|
||||
def copy_to_spoiler(setcode):
|
||||
if os.path.isfile('out/' + setcode + '.xml'):
|
||||
shutil.copy('out/' + setcode + '.xml','out/spoiler.xml')
|
||||
def save_xml(xmlstring, outfile):
|
||||
with open(outfile,'w+') as xmlfile:
|
||||
xmlfile.write(xmlstring)
|
||||
|
||||
if __name__ == '__main__':
|
||||
AllSets = spoilers.get_allsets() #get AllSets from mtgjson
|
||||
@@ -82,6 +82,7 @@ if __name__ == '__main__':
|
||||
[mtgs, errors] = spoilers.errorcheck(mtgs) #check for errors where possible
|
||||
errorlog += errors
|
||||
spoilers.write_xml(mtgs, setinfos['setname'], setinfos['setlongname'], setinfos['setreleasedate'])
|
||||
save_xml(spoilers.pretty_xml(setinfos['setname']), 'out/spoiler.xml')
|
||||
mtgs = spoilers.add_headers(mtgs, setinfos)
|
||||
AllSets = spoilers.make_allsets(AllSets, mtgs, setinfos['setname'])
|
||||
if 'masterpieces' in setinfos: #repeat all of the above for masterpieces
|
||||
@@ -97,4 +98,3 @@ if __name__ == '__main__':
|
||||
save_errorlog(errorlog)
|
||||
save_allsets(AllSets)
|
||||
save_setjson(mtgs)
|
||||
copy_to_spoiler(setinfos['setname'])
|
||||
|
||||
17
spoilers.py
17
spoilers.py
@@ -6,12 +6,12 @@ import sys
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
from lxml import html
|
||||
from lxml import etree
|
||||
from lxml import html, etree
|
||||
from PIL import Image
|
||||
import datetime
|
||||
import urllib
|
||||
import json
|
||||
import xml.dom.minidom
|
||||
|
||||
def scrape_mtgs(url):
|
||||
return requests.get(url, headers={'Cache-Control':'no-cache', 'Pragma':'no-cache', 'Expires': 'Thu, 01 Jan 1970 00:00:00 GMT'}).text
|
||||
@@ -852,14 +852,6 @@ def write_xml(mtgjson, setname, setlongname, setreleasedate, split_cards=[]):
|
||||
|
||||
cardsxml.write("</cards>\n</cockatrice_carddatabase>")
|
||||
|
||||
#failing pretty xml code
|
||||
#with open('out/' + setname + '.xml') as data_file:
|
||||
# tree = etree.parse(data_file)
|
||||
#root = tree.getroot()
|
||||
#f = open('out/' + setname + '.xml', 'w')
|
||||
#f.write(etree.tostring(root, pretty_print=True))
|
||||
#f.close()
|
||||
|
||||
print 'XML STATS'
|
||||
print 'Total cards: ' + str(count)
|
||||
if dfccount > 0:
|
||||
@@ -867,6 +859,11 @@ def write_xml(mtgjson, setname, setlongname, setreleasedate, split_cards=[]):
|
||||
print 'Newest: ' + str(newest)
|
||||
print 'Runtime: ' + str(datetime.datetime.today().strftime('%H:%M')) + ' on ' + str(datetime.date.today())
|
||||
|
||||
def pretty_xml(setcode):
|
||||
prettyxml = xml.dom.minidom.parse('out/' + setcode + '.xml') # or xml.dom.minidom.parseString(xml_string)
|
||||
pretty_xml_as_string = prettyxml.toprettyxml(newl='')
|
||||
return pretty_xml_as_string
|
||||
|
||||
def make_allsets(AllSets, mtgjson, setname):
|
||||
AllSets[setname] = mtgjson
|
||||
return AllSets
|
||||
|
||||
Reference in New Issue
Block a user