Example #1
0
    def serialize(self, downloadsfolder, replacelistforcreatingdestinationpath,
                  showresults):
        from os.path import normpath, basename
        ## ########################
        ## How to get top directory
        import os
        downloadsdir_root = os.path.join(os.getcwd(), downloadsfolder)
        #    import mytools
        #    downloadsdir_bucketdatetime = mytools.mystrings.appendnormaldateddirectorybasedoncurrenttime15(downloadsdir_root)
        #    print(downloadsdir_bucketdatetime)
        #    downloadsdir_hour = os.path.dirname(downloadsdir_bucketdatetime)
        #    print('downloadsdir_hour','=',downloadsdir_hour)
        #    downloadsdir_day = os.path.dirname(downloadsdir_hour)
        #
        ## #############################
        ## directory for processed files
        #replacedirectory = ['\\downloads\\','\\downloadsprocessed\\']

        ## ####################
        ## Process downloads directories
        import readfiltersortserializetobucketdirectories
        iCount = 0
        for root, dirs, files in os.walk(downloadsdir_root):
            for name in dirs:
                downloadsdir_check = os.path.join(root, name)
                iCount = self.countfiles(downloadsdir_check, '.csv')
                print(iCount, downloadsdir_check)
                #        ## ###################################
                if iCount > 0:
                    sourcedirectoryfull = downloadsdir_check
                    sourcebasename = basename(normpath(sourcedirectoryfull))
                    if sourcebasename[:2] != 'x-':
                        o = readfiltersortserializetobucketdirectories.read(
                            sourcedirectoryfull,
                            minpairspreadpercent=0.6,
                            maxvalueatrisk=2.4,
                            maxbidaskspreadpercentagesell=0.25,
                            maxbidaskspreadpercentagebuy=0.25,
                            sortbymeasure='spreadpercentageopen'
                        )  # spreadpercentageopen | valueatriskopen

                        dSerialized = o.DictionaryOfSerializedFileObjects
                        print('------------------------------')
                        print('-- Count of DictionaryOfSerializedFileObjects')
                        print('--  ', len(dSerialized))
                        for k, v in dSerialized.items():
                            oSerialized = v
                            print('--------------')
                            print('-- XMLFilenameOutput')
                            print('--    ', oSerialized.XMLFilenameOutput)
                            if oSerialized.Complete == 1:
                                print('Count', sourcedirectoryfull, iCount)

                                basename = basename(
                                    normpath(sourcedirectoryfull))

                                destinationdirectoryfull = os.path.join(
                                    os.path.dirname(sourcedirectoryfull),
                                    'x-' + basename)
 def serialize(self,downloadsfolder,replacelistforcreatingdestinationpath,showresults):
     ## ########################
     ## How to get top directory
     import os
     downloadsdir_root = os.path.join(os.getcwd(),downloadsfolder)
 #    import mytools
 #    downloadsdir_bucketdatetime = mytools.mystrings.appendnormaldateddirectorybasedoncurrenttime15(downloadsdir_root)
 #    print(downloadsdir_bucketdatetime)
 #    downloadsdir_hour = os.path.dirname(downloadsdir_bucketdatetime)
 #    print('downloadsdir_hour','=',downloadsdir_hour)
 #    downloadsdir_day = os.path.dirname(downloadsdir_hour)
 #    
     ## #############################
     ## directory for processed files
     replacedirectory = ['\\downloads\\','\\downloadsprocessed\\']
     
     ## ####################
     ## Process downloads directories
     import readfiltersortserializetobucketdirectories
     iCount = 0
     for root, dirs, files in os.walk(downloadsdir_root):
         for name in dirs:
             downloadsdir_check = os.path.join(root, name)
             iCount = self.countfiles(downloadsdir_check,'.csv')
             print(iCount,downloadsdir_check)
     #        ## ###################################
             if iCount > 0:
                 sourcedirectoryfull = downloadsdir_check
                 o = readfiltersortserializetobucketdirectories.read(sourcedirectoryfull,
                      minpairspreadpercent = 0.6,
                      maxvalueatrisk = 2.4,
                      maxbidaskspreadpercentagesell = 0.25,
                      maxbidaskspreadpercentagebuy = 0.25,
                      sortbymeasure = 'spreadpercentageopen') # spreadpercentageopen | valueatriskopen
                              
                 dSerialized = o.DictionaryOfSerializedFileObjects
                 print('------------------------------')
                 print('-- Count of DictionaryOfSerializedFileObjects')
                 print('--  ',len(dSerialized))
                 for k,v in dSerialized.items():
                     oSerialized = v            
                     print('--------------')
                     print('-- XMLFilenameOutput')
                     print('--    ',oSerialized.XMLFilenameOutput)
                     if oSerialized.Complete == 1:
                         print('Count',sourcedirectoryfull,iCount)
                         #destinationdirectoryfull = sourcedirectoryfull
                         
                         destinationdirectoryfull = sourcedirectoryfull.replace(replacedirectory[0],replacedirectory[1])
                         import mytools
                         mytools.general.make_sure_path_exists(destinationdirectoryfull)
                         print('Destination',destinationdirectoryfull)
                         import shutil
                         # Move src to dst (mv src dst)
                         shutil.rmtree(destinationdirectoryfull,ignore_errors=True, onerror=None)
                         shutil.move(sourcedirectoryfull, destinationdirectoryfull)
 def serialize(self,downloadsfolder,replacelistforcreatingdestinationpath,showresults):
     from os.path import normpath, basename
     ## ########################
     ## How to get top directory
     import os
     downloadsdir_root = os.path.join(os.getcwd(),downloadsfolder)
 #    import mytools
 #    downloadsdir_bucketdatetime = mytools.mystrings.appendnormaldateddirectorybasedoncurrenttime15(downloadsdir_root)
 #    print(downloadsdir_bucketdatetime)
 #    downloadsdir_hour = os.path.dirname(downloadsdir_bucketdatetime)
 #    print('downloadsdir_hour','=',downloadsdir_hour)
 #    downloadsdir_day = os.path.dirname(downloadsdir_hour)
 #    
     ## #############################
     ## directory for processed files
     #replacedirectory = ['\\downloads\\','\\downloadsprocessed\\']
     
     ## ####################
     ## Process downloads directories
     import readfiltersortserializetobucketdirectories
     iCount = 0
     for root, dirs, files in os.walk(downloadsdir_root):
         for name in dirs:
             downloadsdir_check = os.path.join(root, name)
             iCount = self.countfiles(downloadsdir_check,'.csv')
             print(iCount,downloadsdir_check)
     #        ## ###################################
             if iCount > 0:
                 sourcedirectoryfull = downloadsdir_check
                 sourcebasename = basename(normpath(sourcedirectoryfull))
                 if sourcebasename[:2] !=  'x-':
                     o = readfiltersortserializetobucketdirectories.read(sourcedirectoryfull,
                          minpairspreadpercent = 0.6,
                          maxvalueatrisk = 2.4,
                          maxbidaskspreadpercentagesell = 0.25,
                          maxbidaskspreadpercentagebuy = 0.25,
                          sortbymeasure = 'spreadpercentageopen') # spreadpercentageopen | valueatriskopen
                                  
                     dSerialized = o.DictionaryOfSerializedFileObjects
                     print('------------------------------')
                     print('-- Count of DictionaryOfSerializedFileObjects')
                     print('--  ',len(dSerialized))
                     for k,v in dSerialized.items():
                         oSerialized = v            
                         print('--------------')
                         print('-- XMLFilenameOutput')
                         print('--    ',oSerialized.XMLFilenameOutput)
                         if oSerialized.Complete == 1:
                             print('Count',sourcedirectoryfull,iCount)
                             
                             basename = basename(normpath(sourcedirectoryfull))
                             
                             destinationdirectoryfull = os.path.join(os.path.dirname(sourcedirectoryfull),'x-' + basename)
    def serialize(self, downloadsdirectory,
                  replacelistforcreatingdestinationpath, minpairspreadpercent,
                  maxvalueatrisk, maxbidaskspreadpercentagesell,
                  maxbidaskspreadpercentagebuy, showresults):
        ## ########################
        ## How to get top directory
        import os
        downloadsdir_root = os.path.join(os.getcwd(), downloadsdirectory)
        if showresults == 1:
            print(downloadsdir_root)

    #    import mytools
    #    downloadsdir_bucketdatetime = mytools.mystrings.appendnormaldateddirectorybasedoncurrenttime15(downloadsdir_root)
    #    print(downloadsdir_bucketdatetime)
    #    downloadsdir_hour = os.path.dirname(downloadsdir_bucketdatetime)
    #    print('downloadsdir_hour','=',downloadsdir_hour)
    #    downloadsdir_day = os.path.dirname(downloadsdir_hour)
    #
    ## #############################
    ## directory for processed files
    #replacedirectory = replacelistforcreatingdestinationpath #['\\downloads\\','\\downloadsprocessed\\']

    ## ####################
    ## Process downloads directories
        import readfiltersortserializetobucketdirectories
        iCount = 0
        #        for root, dirs, files in os.walk(downloadsdir_root):
        #            if len(dirs) == 0:
        #                for name in files:
        iCount = 0
        for root, dirs, files in os.walk(downloadsdir_root):
            for name in dirs:
                downloadsdir_check = os.path.join(root, name)
                iCount = self.countfiles(downloadsdir_check, '.csv')
                print('Count of Csv files:', iCount, downloadsdir_check)
                #        for root, dirs, files in os.walk(downloadsdir_root):
                #            for name in dirs:
                #                    downloadsdir_check = os.path.join(root, name)
                #                    iCount = len(files) #self.countfiles(downloadsdir_check,'.csv')
                #                    print('Count of Csv files:',iCount,downloadsdir_check)
                #            #        ## ###################################
                if iCount > 0:
                    sourcedirectoryfull = downloadsdir_check
                    o = readfiltersortserializetobucketdirectories.read(
                        sourcedirectoryfull,
                        minpairspreadpercent=minpairspreadpercent,
                        maxvalueatrisk=maxvalueatrisk,
                        maxbidaskspreadpercentagesell=
                        maxbidaskspreadpercentagesell,
                        maxbidaskspreadpercentagebuy=
                        maxbidaskspreadpercentagebuy,
                        sortbymeasure='spreadpercentageopen'
                    )  # spreadpercentageopen | valueatriskopen

                    self.DictionaryOfSerializedFileObjects = o.DictionaryOfSerializedFileObjects
                    dSerialized = o.DictionaryOfSerializedFileObjects

                    print('------------------------------')
                    print('-- Count of DictionaryOfSerializedFileObjects')
                    print('--  ', len(dSerialized))
                    for k, v in dSerialized.items():
                        oSerialized = v
                        print('--------------')
                        print('-- XMLFilenameOutput')
                        print('--    ', oSerialized.XMLFilenameOutput)
                        if oSerialized.Complete == 1:
                            print('Count', sourcedirectoryfull, iCount)
                            #destinationdirectoryfull = sourcedirectoryfull

                            destinationdirectoryfull = sourcedirectoryfull.replace(
                                replacelistforcreatingdestinationpath[0],
                                replacelistforcreatingdestinationpath[1])
                            import mytools
                            mytools.general.make_sure_path_exists(
                                destinationdirectoryfull)
                            print('Destination', destinationdirectoryfull)
                            import shutil
                            # Move src to dst (mv src dst)
                            shutil.rmtree(destinationdirectoryfull,
                                          ignore_errors=True,
                                          onerror=None)
                            shutil.move(sourcedirectoryfull,
                                        destinationdirectoryfull)
        if file.endswith(extension):  # eg: '.txt'
            count += 1
    return count


iCount = 0
topdirectory = 'C:\Documents and Settings\jmalinchak\My Documents\My Python\Active\py\downloads\\TEST\\01\\15'
print(topdirectory)
for (topdirectory, dirs, files) in os.walk(topdirectory):

    for directoryname in dirs:
        directoryname = os.path.join(topdirectory, directoryname)
        iCount = countfiles(directoryname, '.csv')
        print(str(iCount) + ' ' + directoryname)
        if iCount > 0:
            o = readfiltersortserializetobucketdirectories.read(directoryname)

#    for pathfilename in files:
#        pathfilename = os.path.join(topdirectory,pathfilename)
#        print(pathfilename)
#
#        o1 = deserializecandidatesxml.deserialize('C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\xml\\calendarspreads 20150119053018.xml')
#        d1 = o1.DictionaryOfCandidatesFromXML
#        print(len(d1))
#        for k,v in d1.items():
#            print(k,v['keyid'],v['calculations']['sortbymeasurevalue'],
#                  v['specifications']['symbol'],
#                  v['earlier']['optionsymbol'],
#                  v['earlier']['bucketquotedatetime'],
#                  v['calculations']['sortbymeasurename']
#                  )
    def serialize(self, downloadsdirectory,
                  replacelistforcreatingdestinationpath, minpairspreadpercent,
                  maxvalueatrisk, maxbidaskspreadpercentagesell,
                  maxbidaskspreadpercentagebuy, showresults):
        ## ########################
        ## How to get top directory
        import os
        downloadsdir_root = os.path.join(os.getcwd(), downloadsdirectory)
        if showresults == 1:
            print(downloadsdir_root)

        ## ####################
        ## Process downloads directories
        import readfiltersortserializetobucketdirectories

        dSerializedQuadCandidateXMLPathNames = {}

        iCount = 0
        for root, dirs, files in os.walk(downloadsdir_root):
            for name in dirs:
                downloadsdir_check = os.path.join(root, name)
                iCount = self.countfiles(downloadsdir_check, '.csv')
                print('Count of Csv files:', iCount, downloadsdir_check)
                #        ## ###################################
                if iCount > 0:
                    sourcedirectoryfull = downloadsdir_check
                    print(sourcedirectoryfull)
                    o = readfiltersortserializetobucketdirectories.read(
                        sourcedirectoryfull,
                        minpairspreadpercent=minpairspreadpercent,
                        maxvalueatrisk=maxvalueatrisk,
                        maxbidaskspreadpercentagesell=
                        maxbidaskspreadpercentagesell,
                        maxbidaskspreadpercentagebuy=
                        maxbidaskspreadpercentagebuy,
                        sortbymeasure='spreadpercentageopen'
                    )  # spreadpercentageopen | valueatriskopen

                    self.DictionaryOfSerializedFileObjects = o.DictionaryOfSerializedFileObjects

                    d1 = o.DictionaryOfSerializedFileObjects
                    print(
                        '-- --',
                        'Looping DictionaryOfSerializedFileObjects in runquadbysymbol'
                    )
                    for k1, v1 in d1.items():
                        print('-- --', 'XMLFilenameOutput',
                              v1.XMLFilenameOutput)
                        import deserializecandidatesxml
                        o1 = deserializecandidatesxml.deserialize(
                            v1.XMLFilenameOutput)
                        d1 = o1.DictionaryOfCandidatesFromXML

                        #minpairspreadpercent = 0.4
                        dSortableDictionary = {}

                        import mytools
                        mysymbol = '---'
                        for k1, v1 in d1.items():
                            optiontype1 = mytools.get_from_optionsymbol.optiontype(
                                v1['earlier']['optionsymbol'])
                            if optiontype1 == 'C':
                                for k2, v2 in d1.items():
                                    if v1['specifications'][
                                            'bucketquotedatetime'] == v2[
                                                'specifications'][
                                                    'bucketquotedatetime']:
                                        if v1['specifications']['symbol'] == v2[
                                                'specifications']['symbol']:
                                            mysymbol = v1['specifications'][
                                                'symbol']
                                            optiontype2 = mytools.get_from_optionsymbol.optiontype(
                                                v2['earlier']['optionsymbol'])
                                            if optiontype2 == 'P':
                                                if float(
                                                        v1['calculations']
                                                    ['spreadpercentageopen']
                                                ) > minpairspreadpercent and float(
                                                        v2['calculations']
                                                    ['spreadpercentageopen']
                                                ) > minpairspreadpercent:
                                                    EarlierStrike1 = mytools.get_from_optionsymbol.strike(
                                                        v1['earlier']
                                                        ['optionsymbol'])
                                                    LaterStrike1 = mytools.get_from_optionsymbol.strike(
                                                        v1['later']
                                                        ['optionsymbol'])
                                                    EarlierStrike2 = mytools.get_from_optionsymbol.strike(
                                                        v2['earlier']
                                                        ['optionsymbol'])
                                                    LaterStrike2 = mytools.get_from_optionsymbol.strike(
                                                        v2['later']
                                                        ['optionsymbol'])
                                                    if float(
                                                            EarlierStrike1
                                                    ) > float(
                                                            v1['specifications']
                                                        ['stockprice']
                                                    ) and float(
                                                            LaterStrike1
                                                    ) > float(v1[
                                                            'specifications']
                                                              ['stockprice']):
                                                        if float(
                                                                EarlierStrike2
                                                        ) < float(
                                                                v1['specifications']
                                                            ['stockprice']
                                                        ) and float(
                                                                LaterStrike2
                                                        ) < float(v1[
                                                                'specifications']
                                                                  ['stockprice']
                                                                  ):
                                                            if k1 != k2:
                                                                sumofvalueatrisk = float(
                                                                    v1['calculations']
                                                                    ['valueatriskopen']
                                                                ) + float(
                                                                    v2['calculations']
                                                                    ['valueatriskopen']
                                                                )
                                                                dSortableDictionary[len(
                                                                    dSortableDictionary
                                                                )] = {
                                                                    'sortbymeasurevalue':
                                                                    sumofvalueatrisk,
                                                                    'callcalendarspread':
                                                                    v1,
                                                                    'putcalendarspread':
                                                                    v2,
                                                                    'sortbymeasurename':
                                                                    'valueatrisk'
                                                                }

                        from collections import OrderedDict
                        dOrdered = OrderedDict(
                            sorted(dSortableDictionary.items(),
                                   key=lambda t: t[1]['sortbymeasurevalue']))
                        import serializedictionaryofcalendarspreadquadstoxml
                        oquads = serializedictionaryofcalendarspreadquadstoxml.serialize(
                            sourcedirectoryfull, mysymbol, dOrdered, 1000, 0)

                        #print('got to here 2212')

                        if oquads.Complete == 1 and len(
                                oquads.XMLFilenameOutput) > 0:

                            print("oquads.XMLFilenameOutput=",
                                  oquads.XMLFilenameOutput)
                            dSerializedQuadCandidateXMLPathNames[
                                len(dSerializedQuadCandidateXMLPathNames
                                    )] = oquads.XMLFilenameOutput

                            #print('Count',sourcedirectoryfull,iCount)
                            #destinationdirectoryfull = sourcedirectoryfull

                            destinationdirectoryfull = sourcedirectoryfull.replace(
                                replacelistforcreatingdestinationpath[0],
                                replacelistforcreatingdestinationpath[1])
                            import mytools
                            mytools.general.make_sure_path_exists(
                                destinationdirectoryfull)
                            print('Destination', destinationdirectoryfull)
                            import shutil
                            # Move src to dst (mv src dst)
                            shutil.rmtree(destinationdirectoryfull,
                                          ignore_errors=True,
                                          onerror=None)
                            shutil.move(sourcedirectoryfull,
                                        destinationdirectoryfull)

        print('got here 8181', len(dSerializedQuadCandidateXMLPathNames))

        self.DictionaryOfSerializedQuadCandidateXMLPathNames = dSerializedQuadCandidateXMLPathNames
## Process downloads directories
import readfiltersortserializetobucketdirectories

iCount = 0
for root, dirs, files in os.walk(downloadsdir_root):
    for name in dirs:
        downloadsdir_check = os.path.join(root, name)
        iCount = countfiles(downloadsdir_check, ".csv")
        print(iCount, downloadsdir_check)
        #        ## ###################################
        if iCount > 0:
            sourcedirectoryfull = downloadsdir_check
            o = readfiltersortserializetobucketdirectories.read(
                sourcedirectoryfull,
                minpairspreadpercent=0.6,
                maxvalueatrisk=2.4,
                maxbidaskspreadpercentagesell=0.25,
                maxbidaskspreadpercentagebuy=0.25,
                sortbymeasure="spreadpercentageopen",
            )  # spreadpercentageopen | valueatriskopen

            dSerialized = o.DictionaryOfSerializedFileObjects
            print("------------------------------")
            print("-- Count of DictionaryOfSerializedFileObjects")
            print("--  ", len(dSerialized))
            for k, v in dSerialized.items():
                oSerialized = v
                print("--------------")
                print("-- XMLFilenameOutput")
                print("--    ", oSerialized.XMLFilenameOutput)
                if oSerialized.Complete == 1:
                    print("Count", sourcedirectoryfull, iCount)
#topdirectory = 'C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\downloads\\2015-01-27\\23\\30'
#for subdir, dirs, files in os.walk(rootdir):
#    runningsumofxmlfiles = runningsumofxmlfiles + len(files)
#    for file in files:
#        pathfilenamecandidatexml = os.path.join(subdir, file)

for (topdirectory, dirs, files) in os.walk(topdirectory):
    print('looping ' + topdirectory)
    for sourcedirectoryname in dirs:
        sourcedirectoryfull = os.path.join(topdirectory, sourcedirectoryname)
        iCount = countfiles(sourcedirectoryfull, '.csv')
        #print('loop',sourcedirectoryfull)
        o = readfiltersortserializetobucketdirectories.read(
            sourcedirectoryfull,
            minpairspreadpercent=0.6,
            maxvalueatrisk=2.4,
            maxbidaskspreadpercentagesell=0.25,
            maxbidaskspreadpercentagebuy=0.25,
            sortbymeasure='spreadpercentageopen'
        )  # spreadpercentageopen | valueatriskopen

        dSerialized = o.DictionaryOfSerializedFileObjects
        print('------------------------------')
        print('-- Count of DictionaryOfSerializedFileObjects')
        print('--  ', len(dSerialized))
        for k, v in dSerialized.items():
            oSerialized = v
            print('--------------')
            print('-- XMLFilenameOutput')
            print('--    ', oSerialized.XMLFilenameOutput)
            if oSerialized.Complete == 1:
                print('Count', sourcedirectoryfull, iCount)
    def serialize(self,
                     downloadsdirectory ,
                     replacelistforcreatingdestinationpath ,
                     minpairspreadpercent ,
                     maxvalueatrisk ,
                     maxbidaskspreadpercentagesell ,
                     maxbidaskspreadpercentagebuy ,
                     showresults
                 ):
        ## ########################
        ## How to get top directory
        import os
        downloadsdir_root = os.path.join(os.getcwd(),downloadsdirectory)
        if showresults == 1:
            print(downloadsdir_root)

        
        ## ####################
        ## Process downloads directories
        import readfiltersortserializetobucketdirectories

        dSerializedQuadCandidateXMLPathNames = {}
        
        iCount = 0
        for root, dirs, files in os.walk(downloadsdir_root):
            for name in dirs:
                downloadsdir_check = os.path.join(root, name)
                iCount = self.countfiles(downloadsdir_check,'.csv')
                print('Count of Csv files:',iCount,downloadsdir_check)
                #        ## ###################################
                if iCount > 0:
                    sourcedirectoryfull = downloadsdir_check
                    print(sourcedirectoryfull)
                    o = readfiltersortserializetobucketdirectories.read(sourcedirectoryfull,
                         minpairspreadpercent = minpairspreadpercent,
                         maxvalueatrisk = maxvalueatrisk,
                         maxbidaskspreadpercentagesell = maxbidaskspreadpercentagesell,
                         maxbidaskspreadpercentagebuy = maxbidaskspreadpercentagebuy,
                         sortbymeasure = 'spreadpercentageopen') # spreadpercentageopen | valueatriskopen
                    
                    self.DictionaryOfSerializedFileObjects = o.DictionaryOfSerializedFileObjects

                    d1 = o.DictionaryOfSerializedFileObjects
                    print('-- --','Looping DictionaryOfSerializedFileObjects in runquadbysymbol')
                    for k1,v1 in d1.items():
                        print('-- --','XMLFilenameOutput',v1.XMLFilenameOutput)
                        import deserializecandidatesxml
                        o1 = deserializecandidatesxml.deserialize(v1.XMLFilenameOutput)
                        d1 = o1.DictionaryOfCandidatesFromXML
                    
                        #minpairspreadpercent = 0.4
                        dSortableDictionary = {}
                    
                        import mytools
                        mysymbol = '---'
                        for k1,v1 in d1.items():
                            optiontype1 = mytools.get_from_optionsymbol.optiontype(v1['earlier']['optionsymbol'])
                            if optiontype1 == 'C':
                                for k2,v2 in d1.items():
                                    if v1['specifications']['bucketquotedatetime'] == v2['specifications']['bucketquotedatetime']:
                                        if v1['specifications']['symbol'] == v2['specifications']['symbol']:
                                            mysymbol = v1['specifications']['symbol']
                                            optiontype2 = mytools.get_from_optionsymbol.optiontype(v2['earlier']['optionsymbol'])
                                            if optiontype2 == 'P':
                                                if float(v1['calculations']['spreadpercentageopen']) > minpairspreadpercent and float(v2['calculations']['spreadpercentageopen']) > minpairspreadpercent:
                                                    EarlierStrike1 = mytools.get_from_optionsymbol.strike(v1['earlier']['optionsymbol'])
                                                    LaterStrike1 = mytools.get_from_optionsymbol.strike(v1['later']['optionsymbol'])
                                                    EarlierStrike2 = mytools.get_from_optionsymbol.strike(v2['earlier']['optionsymbol'])
                                                    LaterStrike2 = mytools.get_from_optionsymbol.strike(v2['later']['optionsymbol'])
                                                    if float(EarlierStrike1) > float(v1['specifications']['stockprice']) and float(LaterStrike1) > float(v1['specifications']['stockprice']):
                                                        if float(EarlierStrike2) < float(v1['specifications']['stockprice']) and float(LaterStrike2) < float(v1['specifications']['stockprice']):
                                                            if k1 != k2:
                                                                sumofvalueatrisk = float(v1['calculations']['valueatriskopen']) + float(v2['calculations']['valueatriskopen'])
                                                                dSortableDictionary[len(dSortableDictionary)] = {'sortbymeasurevalue' : sumofvalueatrisk, 'callcalendarspread' : v1, 'putcalendarspread' : v2, 'sortbymeasurename' : 'valueatrisk'}
                            
                        from collections import OrderedDict
                        dOrdered = OrderedDict(sorted(dSortableDictionary.items(), key=lambda t: t[1]['sortbymeasurevalue']))
                        import serializedictionaryofcalendarspreadquadstoxml
                        oquads = serializedictionaryofcalendarspreadquadstoxml.serialize(sourcedirectoryfull,mysymbol,dOrdered,1000,0)

                        #print('got to here 2212')
                                                
                        if oquads.Complete == 1 and len(oquads.XMLFilenameOutput)>0:
                            
                            print("oquads.XMLFilenameOutput=",oquads.XMLFilenameOutput)
                            dSerializedQuadCandidateXMLPathNames[len(dSerializedQuadCandidateXMLPathNames)] = oquads.XMLFilenameOutput
                            
                            #print('Count',sourcedirectoryfull,iCount)
                            #destinationdirectoryfull = sourcedirectoryfull
                            
                            destinationdirectoryfull = sourcedirectoryfull.replace(replacelistforcreatingdestinationpath[0],replacelistforcreatingdestinationpath[1])
                            import mytools
                            mytools.general.make_sure_path_exists(destinationdirectoryfull)
                            print('Destination',destinationdirectoryfull)
                            import shutil
                            # Move src to dst (mv src dst)
                            shutil.rmtree(destinationdirectoryfull,ignore_errors=True, onerror=None)
                            shutil.move(sourcedirectoryfull, destinationdirectoryfull)
                            
        print('got here 8181',len(dSerializedQuadCandidateXMLPathNames))                
        
        self.DictionaryOfSerializedQuadCandidateXMLPathNames = dSerializedQuadCandidateXMLPathNames
                                             
  for file in list_dir:
    if file.endswith(extension): # eg: '.txt'
      count += 1
  return count
  
iCount = 0
topdirectory = 'C:\Documents and Settings\jmalinchak\My Documents\My Python\Active\py\downloads\\TEST\\01\\15'
print(topdirectory)
for (topdirectory, dirs, files) in os.walk(topdirectory):
    
    for directoryname in dirs:
        directoryname = os.path.join(topdirectory,directoryname)
        iCount = countfiles(directoryname,'.csv')
        print(str(iCount) + ' ' + directoryname)
        if iCount > 0:
            o = readfiltersortserializetobucketdirectories.read(directoryname)
        
#    for pathfilename in files:
#        pathfilename = os.path.join(topdirectory,pathfilename)
#        print(pathfilename)
#
#        o1 = deserializecandidatesxml.deserialize('C:\\Documents and Settings\\jmalinchak\\My Documents\\My Python\\Active\\py\\output\\xml\\calendarspreads 20150119053018.xml')
#        d1 = o1.DictionaryOfCandidatesFromXML
#        print(len(d1))
#        for k,v in d1.items():
#            print(k,v['keyid'],v['calculations']['sortbymeasurevalue'],
#                  v['specifications']['symbol'],
#                  v['earlier']['optionsymbol'],
#                  v['earlier']['bucketquotedatetime'],
#                  v['calculations']['sortbymeasurename']
#                  )