samedi 13 juin 2020

How to make my code stops when conditions are met

            for i in range(len(employeesChosen)):
                info = get_employee_info(employeesChosen[i])
                event_done=False
                if employeesChosen[i] not in currentEmployees and check_employee_availability(service,employeesChosen[i],currentStart,currentEnd,currentStart,calendarEnd):
                    event_done=True
                else:
                    for event in events:
                        if employeesChosen[i] == event['summary']:

                            if str2datetime(currentStart) == str2datetime(event['start']['dateTime'].split('+')[0]) and str2datetime(currentEnd) == str2datetime(event['end']['dateTime'].split('+')[0]):
                                event_done = False

                            if str2datetime(currentStart) < str2datetime(event['end']['dateTime'].split('+')[0]):  #rdv avant un qui est deja set
                                event_info = {'location': get_company_location(event['description']),'datetime': event['end']['dateTime'].split('+')[0]}
                                start_first_event = {'location': get_company_location(event['description']),'datetime': event['start']['dateTime'].split('+')[0]}
                                event_fabricant_info = {'location': get_company_location(event_fabricant),'datetime': currentStart}
                                end_second_event = {'location': get_company_location(event_fabricant),'datetime': currentEnd}
                                if check_event_possibility_if_before(event_info, event_fabricant_info, end_second_event, start_first_event, info[0]):
                                    event_done = True
                                else:
                                    event_done = False

                            if str2datetime(currentStart) > str2datetime(event['end']['dateTime'].split('+')[0]) or str2datetime(currentEnd): #rdv apres un qui est deja set
                                event_info={'location': get_company_location(event['description']), 'datetime': event['end']['dateTime'].split('+')[0]}
                                start_first_event ={'location': get_company_location(event['description']), 'datetime': event['start']['dateTime'].split('+')[0]}
                                event_fabricant_info = {'location': get_company_location(event_fabricant), 'datetime': currentStart}
                                end_second_event = {'location': get_company_location(event_fabricant), 'datetime': currentEnd}
                                if check_event_possibility(event_info, event_fabricant_info, end_second_event,start_first_event, info[0]):
                                    event_done=True
                                else:
                                    event_done=False

I'm having some issues I hope you guys will help resolve. I'm new to python so please forgive my question if it already been answered a couple times.

I would like to know, below the statement if employeesChosen[i] == event['summary']: , how to make every if run only once? Right now, even if the first condition = False, it will keep on running until the end. I would like the code to only lock on one of the if conditions. The for will loops 3 times.

Aucun commentaire:

Enregistrer un commentaire