gpt4 book ai didi

python - 忙/闲查询

转载 作者:太空宇宙 更新时间:2023-11-03 15:22:36 26 4
gpt4 key购买 nike

根据https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query处的文档要执行空闲/忙碌查询,您必须在正文中提供以下参数:

{
"timeMin": datetime,
"timeMax": datetime,
"timeZone": string,
"groupExpansionMax": integer,
"calendarExpansionMax": integer,
"items": [
{
"id": string
}
]
}

构建查询时:

# calendarlist = a list with all the ids of the calendars I do query
# calendar is the access token to google calendar API
start = datetime.now()
end = start.replace(hour=23)
freebusy_query = {
"timeMin": start,
"timeMax": end,
"timeZone": 'Europe/Madrid',
"items": calendarlist
}

availability = calendar.freebusy().query(body=freebusy_query).execute()

我收到的回复告诉我:

TypeError: datetime.datetime(2017, 4, 14, 23, 00, 59, 999999)) is not JSON serializable

所以我猜我对文档的阅读是错误的,我必须提供的是日期时间字符串

我说得对吗?

将日期时间转换为字符串时如何保留 tzinfo?

date_format = '%Y-%m-%dT%H:%M:%S.%f%Z'
start_string = start.strftime(date_format)
...

最佳答案

试试这个

start = datetime.now().replace(microsecond=0).isoformat() + "-04:00"
end = datetime.now().replace(hour=23, microsecond=0).isoformat() + "-04:00"



freebusy = service.freebusy().query(body=
{"timeMin": start,
"timeMax": end,
"timeZone": 'Europe/Madrid',
"items": calendarList
}).execute()

关于python - 忙/闲查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43407096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com