Explorar o código

Change updateEntry to updateAndValidateEntry which for entries returning False skips them

Andrej hai 1 mes
pai
achega
64117ec0bc
Modificáronse 1 ficheiros con 8 adicións e 5 borrados
  1. 8 5
      importXLSX.py

+ 8 - 5
importXLSX.py

@@ -53,6 +53,7 @@ def getFields(pars):
       try:
          dsgnFields[f].update({x:mdFields[f][x] for x in copyFields})
       except KeyError:
+#    print('{}: {}'.format(p,len(pMap[p])))
          pass
    return dsgnFields
 
@@ -313,17 +314,17 @@ def convertLookup(xlsColumnName):
 def rowValid(df,r):
    return True
 
-def updateEntry(e):
-   pass
+def updateAndValidateEntry(e):
+   return True
 
 def importData(pars,filename,getId=getId,modify=modify,\
    convertLookup=convertLookup,dryRun=True,debug=True,
-   rowValid=rowValid,updateEntry=updateEntry):
+   rowValid=rowValid,updateAndValidateEntry=updateAndValidateEntry):
 #master routine that imports data based on pars, 
 #applies user supplied functions modify, convertLookup and get Id and 
 #updates relevant database
 #rowValid signals a valid row, argument is current row from xlsx
-#updateEntry adds fields that can be computed from other fields in entry
+#updateAndValidateEntry can add fields that can be computed from other fields in entry and allows to reject entries not matching a target pattern
 
 #some useful fields from pars (d is for default value)
 # - skiprows removes irelevant rows (number, d: 0)
@@ -420,7 +421,9 @@ def importData(pars,filename,getId=getId,modify=modify,\
          entry['Date']=entry[dateVariable]
       except KeyError:
          pass
-      updateEntry(entry)
+      
+      if not updateAndValidateEntry(entry):
+         continue
 
       entries.append(entry)