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>

there were multiple issues with my code that are not fixed and running properly

XML=('<?xml version="1.0" encoding="UTF-8"?><RequestBatch ConsumerKey="WebCommXML" Password="IN4"><Request RequestID="GetScanCodesByDate" Company="01"><Company>01</Company><FromDate>_STARTDATE_</FromDate><ToDate>_ENDDATE_</ToDate></Request></RequestBatch>').replace('_STARTDATE_', args.orderDate).replace('_ENDDATE_', args.endDate)
r = requests.post(facts_url, data=XML, stream=True)
with open(args.destDir + '/FACTSscancode_'+args.fileDate+'.xml', 'w') as f:
    print >> f, r.text
#impliment scan code retrival api[finished]
#two loops first to collect all order numbers in list second loop to retrive order numbers to avoid duplicate retrivals[]
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] = order
This question has already been answered. Start a new discussion instead.