outLines = [] date_col = 3 type= 'AV1451' with open('/home/sulantha/Downloads/22_Aug_TAU_AMY.csv', 'r') as file: next(file) for line in file: row = line.split(',') rid = row[0].split('_')[-1] date = row[date_col].strip() if date == '': continue dateT = datetime.strptime(date, '%m/%d/%Y') dateS = dateT.strftime('%Y-%m-%d') findSQLV2 = "SELECT CONVERTED_FOLDER FROM Conversion WHERE RID = {0} AND SCAN_TYPE = '{3}' AND SCAN_DATE = '{1}' AND VERSION = '{2}' LIMIT 1".format( rid, dateS, 'V2', type.upper()) resv2 = DBClient.executeSomeResults(findSQLV2, 1) if len(resv2) is 0: print(rid) v2Path = '' elif len(resv2) == 1: v2Path = '{0}/*_{1}.mnc'.format(resv2[0][0], type.upper()) v2Path = glob.glob(v2Path)[0] findanyT1 = "SELECT ROOT_FOLDER FROM Processing WHERE RID = {0} AND MODALITY = '{1}' AND PROCESSED = 1 AND QCPASSED = 1 ORDER BY SCAN_DATE DESC LIMIT 1".format( rid, 'T1') t1 = DBClient.executeSomeResults(findanyT1, 1) if len(t1) is 0: t1_path = '' elif len(t1) == 1: t1_path = '{0}/civet'.format(t1[0][0])