[英]How to add another condition in a for loop
我正在编写一个在谷歌日历中创建事件的程序。
我的 python 代码已连接到 MySQL 数据库。
每家公司都有 3 名员工分配给它。 如果第一个员工很忙,它会检查第二个员工,如果他也很忙,它会检查第三个员工。
该代码有效,但公司名称出现在event['description']
中。 我的代码只检查由员工代表的event['summary']
。 因此,如果第一个员工很忙,请检查下一个,依此类推..
我的问题是,如果我为同一家公司添加另一个约会,并且如果其中一名员工仍然有空,它将添加该事件。 所以我会在日历中看到当时同一家公司的 2 项活动。
我想要的是,如果公司( event_description
)== event['description']
然后不要创建事件
我尝试了一些不起作用的方法:
currentEmployees = []
found_match = False
for event in events:
currentEmployees.append(event['summary'])
for i in range(3):
event_summary = row[i+1]
if event_inspecteur not in currentEmployees and event['description'] != event_fabricant :
event = {
'summary': event_summary,
'location': event_location,
'description': event_description,
'start': {
'dateTime': event_start,
'timeZone': 'America/New_York',
},
'end': {
'dateTime': event_end,
'timeZone': 'America/New_York',
},
'attendees': [
{'email': event_email},
],
'reminders': {
'useDefault': True,
},
}
print('Nouveau RDV creer')
event = service.events().insert(calendarId='primary', body=event).execute()
break
else:
print("La plage horraire est deja prise par : ")
start = event['start'].get('dateTime', event['start'].get('date'))
print(start, "Fabricant: " + event['description'], "/// " + "Inspecteur: " + event['summary'], "/// " + "Location: " + event['location'])
pass
if event_inspecteur not in currentEmployees and event['description']:= event_fabricant :
在下面给了我这个错误,因为我添加了and event['description']:= event_fabricant :
if event_inspecteur not in currentEmployees and event['description'] != event_fabricant :
UnboundLocalError: local variable 'event' referenced before assignment
我只需要添加另一个列表。
currentEmployees = []
currentCompany = []
found_match = False
for event in events:
currentEmployees.append(event['summary'])
currentCompany.append(event['description'])
for i in range(3):
event_inspecteur = row[i+1]
if event_inspecteur not in currentEmployees and event_fabricant not in currentCompany:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.