-
-
Save jayd3e/3106404 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, shutil, csv | |
from xml.dom import minidom | |
from xml.etree import ElementTree as ET | |
from jinja2 import Template, Environment, PackageLoader | |
env = Environment(loader=PackageLoader('main', 'templates')) | |
template = env.get_template('template.html') | |
fileList = os.listdir('./data') | |
def get_XML_Files(fileList): | |
for f in fileList: | |
goodList = [] | |
extension = f[-4:-1] | |
if extension == '.xml': | |
goodList.append(f) | |
return goodList | |
fileList = get_XML_Files(fileList) | |
outFile = open('output.html', 'w') | |
for f in fileList: | |
orderList = [] | |
myFile = open('./data/' + f, 'rb') | |
data = myFile.read().replace('&', '&') | |
element = ET.XML(data) | |
for node in element.findall('order'): | |
items = [] | |
store = node[68].text.split('\n') | |
order = { | |
'date': node[6].text, | |
'invoice': node[3].text, | |
'tax_total': "%0.2f" % float(node[10].text) | |
'shipping_total': "%0.2f" % float(node[11].text) | |
'discount_total': "%0.2f" % float(node[12].text) | |
'subtotal': "%0.2f" % float(node[13].text) | |
'grand_total': "%0.2f" % float(node[14].text) | |
'ship_method': node[65].text | |
'email': node[58].text | |
'store': store[0] | |
} | |
billing = { | |
'firstname': node[77][11].text, | |
'lastname': node[77][12].text, | |
'company': node[77][13].text, | |
'street': node[77][14].text, | |
'city': node[77][15].text, | |
'region': node[77][16].text, | |
'postcode': node[77][17].text, | |
'country': node[77][18].text, | |
'phone': node[77][19].text | |
} | |
shipping = { | |
'firstname': node[78][11].text, | |
'lastname': node[78][12].text, | |
'company': node[78][13].text, | |
'street': node[78][14].text, | |
'city': node[78][15].text, | |
'region': node[78][16].text, | |
'postcode': node[78][17].text, | |
'country': node[78][18].text, | |
'phone': node[78][19].text | |
} | |
payment.method': node[79][13].text | |
for line in node[80]: | |
item = { | |
'qty': "%0.0f" % float(line[22].text), | |
'name': line[12].text | |
'sku': line[11].text | |
'price': "%0.2f" % float(line[26].text) | |
'discount': "%0.2f" % float(line[37].text) | |
'tax': "%0.2f" % float(line[32].text) | |
'total_price': "%0.2f" % float(line[42].text) | |
} | |
items.append(item) | |
order['shipping'] = shipping | |
order['billing'] = billing | |
order['payment'] = payment | |
order['items'] = items | |
orderList.append(order) | |
output = template.render(orderList = orderList) | |
outFile.write(output) | |
outFile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment