SO i have a python code that collects xml data in a file then seraches the file for the scancode and once it finds that the scan code is there it starts scanning for the order number this is where im running into trouble at. What i want it to do is when it gets the order number it stores it so that when it loops back though to see the next number it sees that the first one was stored and over writes it or just skips it entierly. I have been trying a way i thought was correct but i keep getting one of two erros each time i run it. The first error is "TypeError: unsupported operand type(s) for +: 'bool' and 'str'" and the second error is "ValueError: invalid literal for int() with base 10: 'D02067'". IF someone could help em figure this out i would be greatly appriative.
import email,getpass,imaplib,os,sys,re,random,StringIO,argparse,requests, json,datetime, csv
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders
from email.Utils import COMMASPACE, formatdate
from collections import OrderedDict
from xml.dom import minidom
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
from collections import namedtuple
parser = argparse.ArgumentParser(description='Process today\'s FACTS orders and create CSV files usable by CYFE')
parser.add_argument(
'-p'
, help='The directory where the CSV files will be placed'
, required=False
, dest='destDir'
, metavar='Destination directory'
, default='/tmp/cyfe'
)
parser.add_argument(
'-d'
, help='The start date to process orders for'
, required=False
, dest='orderDate'
, metavar='Order date'
, default=datetime.datetime.now().strftime("%Y%m%d")
)
parser.add_argument(
'-e'
, help='The start date to process orders for'
, required=False
, dest='endDate'
, metavar='Order End date'
, default=datetime.datetime.now().strftime("%Y%m%d")
)
parser.add_argument(
'-f'
, help='The date for file name'
, required=False
, dest='fileDate'
, metavar='File Date'
, default=datetime.datetime.now().strftime("%Y%m%d_%I%M")
)
args = parser.parse_args()
ordernumber={'order':True}
tree = ET.parse(args.destDir + '/FACTSscancode_'+args.fileDate+'.xml')
root=tree.getroot()
codeList = root.findall(".//ScanCodes/ScanCode")
for el in codeList:
code = el.find('Code').text
if code != None:
order = el.find('OrderNumber').text
if order != None:
ordernumber['order'] = ordernumber['order'] + order
This is how the xml file is formated.
<ScanCodes>
<ScanCode>
<OrderNumber></OrderNumber>
<Code></Code>
<User></User>
<DateTime></DateTime>
<LineNumber></LineNumber>
<Comment></Comment>
<SeqNumber></SeqNumber>