1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| def extractNewResa(self, file):
flag = True
complete_path = file
file = file.split('/')
file = file[len(file) - 1]
num = file.split('-')[0]
numTT = num.split(' ')
if numTT[0] != "TT" or numTT[1].isdigit() == False:
self.tab_new_resa = TITLE_ERROR
fast_ref = "FAST0" + numTT[1]
wb = xlrd.open_workbook(RESA)
sheet_src = wb.sheet_by_index(0)
for row_index in range(sheet_src.nrows):
if sheet_src.cell_value(row_index, 1) == fast_ref:
flag = False
if flag:
wb = xlrd.open_workbook(complete_path)
check_flag = False
poq_flag = False
sheet = wb.sheet_by_name("Réservation")
dict_resa = {}
self.tab_new_resa = []
date = datetime.date
dict_resa[Col_Type] = "réservation"
dict_resa[Col_TT] = fast_ref
dict_resa[Col_App] = sheet.cell_value(4, 2)
dict_resa[Col_Lib] = sheet.cell_value(5, 2)
dict_resa[Col_Statut] = "A valider"
objDate = Date(wb, sheet.cell_type(7, 2), sheet.cell_value(7, 2))
dict_resa[Col_MeP] = objDate.getDate()
dict_resa[Col_Demand] = sheet.cell_value(3, 2)
dict_resa[Col_TTdate] = date.today().strftime('%d/%m/%Y')
dict_resa[Col_Gecsi] = sheet.cell_value(8, 2)
dict_resa[Col_Version] = sheet.cell_value(9, 2)
dict_resa[Col_Adh] = sheet.cell_value(sheet.nrows-1, 2)
checkbox_sheet = wb.sheet_by_name("CheckBox")
if checkbox_sheet.cell_value(10, 1) == 1:
check_flag = True
resto = {}
nbEmp = int(checkbox_sheet.cell_value(19, 4))
dict_resa[Col_PEmp] = checkbox_sheet.cell_value(17, 5)
resto[checkbox_sheet.cell_value(18, 6)] = checkbox_sheet.cell_value(18, 5)
for i in range(20, 20+nbEmp):
if checkbox_sheet.cell_value(i, 5) == "":
break
resto[checkbox_sheet.cell_value(i, 6)] = checkbox_sheet.cell_value(i, 5)
else:
self.tab_new_resa = EXISTING_TT
if checkbox_sheet.cell_value(9, 1) == 1:
notes = sheet.cell_note_map
nameObj = wb.name_and_scope_map.get(('datesdisponibilite', -1))
y = nameObj.area2d()[1:5][0]
x = nameObj.area2d()[1:5][2]
if notes[y, x].text != None:
poq_flag = True
poq = notes[y, x].text
list_poq = poq.split('\n')
dict_poq = {}
for i in list_poq:
dict_poq[i.split(' ')[1]] = i
myMinResa = wb.name_and_scope_map.get(('deb', -1)).area2d()[1:5]
myMaxResa = wb.name_and_scope_map.get(('fin', -1)).area2d()[1:5]
list_dict_cadre = []
for i in range(myMinResa[0]+1, myMaxResa[0]):
dict_cadre = {}
if sheet.cell_value(i, 1) != None:
util = sheet.cell_value(i, 1)
cadre = sheet.cell_value(i, 2)
objDate = Date(wb, sheet.cell_type(i, 3), sheet.cell_value(i, 3))
deb = objDate.getDate()
objDate = Date(wb, sheet.cell_type(i, 4), sheet.cell_value(i, 4))
fin = objDate.getDate()
if deb != None and fin != None:
dict_cadre[Col_Util] = util
dict_cadre[Col_Deb] = deb
dict_cadre[Col_Fin] = fin
dict_cadre[Col_Cadre] = cadre
list_dict_cadre.append(dict_cadre)
L = []
for element in list_dict_cadre:
for key, value in element.items():
dict_resa[key] = value
if check_flag:
dict_resa[Col_REmp] = resto[element[11].lower()]
if poq_flag:
dict_resa[Col_POQ] = dict_poq[element[11]]
L.append(dict_resa)
print(dict_resa)
print(L) |
Partager