Sfoglia il codice sorgente

Adding parseDate to account for change of date format from newer versions of labkey

NIX User 7 ore fa
parent
commit
5061002916
1 ha cambiato i file con 11 aggiunte e 1 eliminazioni
  1. 11 1
      pythonScripts/populateImagingFromTransferList.py

+ 11 - 1
pythonScripts/populateImagingFromTransferList.py

@@ -10,6 +10,16 @@ import sys
 import datetime
 import re
 
+def parseDate(x):
+    patterns=['%Y/%m/%d %H:%M:%S','%Y-%m-%d %H:%M:%S.%f']
+    for p in patterns:
+        try:
+            return datetime.datetime.strptime(x,p)
+        except ValueError:
+            pass
+    raise ValueError('parseDate could not find an appropriate pattern')
+    return None
+
 def main(parameterFile):
     fhome=os.path.expanduser('~')
     fsetup=os.path.join(fhome,'.labkey','setup.json')
@@ -117,7 +127,7 @@ def main(parameterFile):
         #this is part of QA and is reported in missingImages Schema/Query
     
         #convert dates
-        sDates={r['orthancSeries']:datetime.datetime.strptime(r['studyDate'],'%Y/%m/%d %H:%M:%S') 
+        sDates={r['orthancSeries']:parseDate(r['studyDate']) 
                 for r in dsOrthanc['rows']}
 
         sDates={x:sDates[x].strftime('%Y%m%d') for x in sDates}