使用 python 从 google 日历事件中提取与会者响应
Extract attendee response from google calendar event with python
这是 wpercy 和 Kieran 最近回答的问题的后续问题。
我正在尝试设计一些 Python 代码来改进 Zapier 中的 Zap。
第一阶段涉及从提供的(由 Google)字符串变量中提取与会者电子邮件,其中包含以逗号分隔的电子邮件。
我现在需要弄清楚的是如何提取与会者的回复并将它们配对,或者以某种方式让他们在执行 Zap 中的其余步骤时遵循相应的与会者电子邮件地址,每个 email/attendee.
这是我测试成功的解决方案代码。它只处理电子邮件:
emails = []
attendeeList = input_data['attendeeEmails'].split(',')
for email in attendeeList:
a = {'Email' : email.strip()}
emails.append(a)
return emails
这是 Kieran 提供的另一个解决方案:
[{'Email': email.strip()} for email in input_data['attendeeEmails'].split(',')]
Google 日历数据如下所示:
attendees:
1:
displayName: Doug Christensen
email: xxxx@gmail.com
responseStatus: needsAction
2:
displayName: Doug Christensen
email: yyyyyy@gmail.com
responseStatus: needsAction
3:
self: true
email: zzzz@xyzmadscience.com
organizer: true
responseStatus: accepted
所以我想得到 "responseStatus",我唯一能想到的就是以下内容:
emails = []
position = 0
responseList = input_data['attendeeReponses'].split(',')
attendeeList = input_data['attendeeEmails'].split(',')
for email in attendeeList:
a = {'Email' : email.strip(), 'responseStatus' : reponseStatus(position).strip()}
a = {'Email' : email.strip()}
emails.append(a)
position += 1
return emails
...但这不起作用(在 Zapier 中说 "error")。
我对与会者电子邮件在 2 Google 个变量 "Attendee Emails" 和 "Attendees Email" 中可用这一事实感到非常困惑。一个实际上显示在传递给 Zap 的 Python 代码的变量中作为 'Attendees[]Email',而另一个显示为 'Attendee Emails'。对于与会者的回应,只有一个选项显示为 'Attendees[]ResponseStatus'。
我显然不是专家,但这些标签向我暗示了一些数据结构?当包含“[]”时,让我觉得可以使用一种更优雅的方法来提取电子邮件并与与会者的回复配对。
我希望 Python 代码能够 return 电子邮件及其相应的与会者回复,以便对每个 email/response 对执行一次以下 Zap 步骤。
再一次,任何指导将不胜感激。
道格
您出错的原因是您试图访问列表中带括号 ()
的元素。您应该使用方括号 []
。
即使在修复该问题之后,您也可以以更加 pythonic 的方式执行此操作。您不应使用自己的变量来跟踪您在列表中的位置,而应使用 built-in 函数 enumerate()
。这将为您跟踪索引,您不必手动增加它。
你会像这样使用它
emails = []
responseList = input_data['attendeeReponses'].split(',')
attendeeList = input_data['attendeeEmails'].split(',')
for i,email in enumerate(attendeeList):
a = {'Email': email.strip(), 'responseStatus': reponseStatus[i].strip()}
emails.append(a)
return emails
这是 wpercy 和 Kieran 最近回答的问题的后续问题。 我正在尝试设计一些 Python 代码来改进 Zapier 中的 Zap。 第一阶段涉及从提供的(由 Google)字符串变量中提取与会者电子邮件,其中包含以逗号分隔的电子邮件。
我现在需要弄清楚的是如何提取与会者的回复并将它们配对,或者以某种方式让他们在执行 Zap 中的其余步骤时遵循相应的与会者电子邮件地址,每个 email/attendee.
这是我测试成功的解决方案代码。它只处理电子邮件:
emails = []
attendeeList = input_data['attendeeEmails'].split(',')
for email in attendeeList:
a = {'Email' : email.strip()}
emails.append(a)
return emails
这是 Kieran 提供的另一个解决方案:
[{'Email': email.strip()} for email in input_data['attendeeEmails'].split(',')]
Google 日历数据如下所示:
attendees:
1:
displayName: Doug Christensen
email: xxxx@gmail.com
responseStatus: needsAction
2:
displayName: Doug Christensen
email: yyyyyy@gmail.com
responseStatus: needsAction
3:
self: true
email: zzzz@xyzmadscience.com
organizer: true
responseStatus: accepted
所以我想得到 "responseStatus",我唯一能想到的就是以下内容:
emails = []
position = 0
responseList = input_data['attendeeReponses'].split(',')
attendeeList = input_data['attendeeEmails'].split(',')
for email in attendeeList:
a = {'Email' : email.strip(), 'responseStatus' : reponseStatus(position).strip()}
a = {'Email' : email.strip()}
emails.append(a)
position += 1
return emails
...但这不起作用(在 Zapier 中说 "error")。
我对与会者电子邮件在 2 Google 个变量 "Attendee Emails" 和 "Attendees Email" 中可用这一事实感到非常困惑。一个实际上显示在传递给 Zap 的 Python 代码的变量中作为 'Attendees[]Email',而另一个显示为 'Attendee Emails'。对于与会者的回应,只有一个选项显示为 'Attendees[]ResponseStatus'。
我显然不是专家,但这些标签向我暗示了一些数据结构?当包含“[]”时,让我觉得可以使用一种更优雅的方法来提取电子邮件并与与会者的回复配对。
我希望 Python 代码能够 return 电子邮件及其相应的与会者回复,以便对每个 email/response 对执行一次以下 Zap 步骤。
再一次,任何指导将不胜感激。
道格
您出错的原因是您试图访问列表中带括号 ()
的元素。您应该使用方括号 []
。
即使在修复该问题之后,您也可以以更加 pythonic 的方式执行此操作。您不应使用自己的变量来跟踪您在列表中的位置,而应使用 built-in 函数 enumerate()
。这将为您跟踪索引,您不必手动增加它。
你会像这样使用它
emails = []
responseList = input_data['attendeeReponses'].split(',')
attendeeList = input_data['attendeeEmails'].split(',')
for i,email in enumerate(attendeeList):
a = {'Email': email.strip(), 'responseStatus': reponseStatus[i].strip()}
emails.append(a)
return emails