You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现Google Calendar事件描述自动轮换每周主讲人?

实现Google日历事件描述自动轮换主讲人

以下两种工具方案可以满足你的需求:

1. Google Apps Script(谷歌生态内原生实现,无需额外环境)

这是最省心的方式,直接用谷歌自带的脚本工具绑定日历操作:

  • 打开Google日历,找到目标重复事件,从事件详情页的URL中提取事件ID(URL末尾的一串字符)
  • 打开Google Apps Script平台,新建一个空白脚本项目
  • 替换默认代码为以下内容(将你的轮换逻辑转为JavaScript,同时修正了原Python代码中变量未定义的问题):
function updateWeeklySpeaker() {
  const speakers = ['Person 1', 'Person 2', 'Person 3'];
  const targetEventId = '替换为你的事件ID';
  
  const now = new Date();
  // 获取当前年份的周数
  const weekNum = Utilities.formatDate(now, Session.getScriptTimeZone(), "w");
  const currentSpeaker = speakers[weekNum % speakers.length];
  
  const calendar = CalendarApp.getDefaultCalendar();
  const event = calendar.getEventById(targetEventId);
  
  // 保留原有描述并追加主讲人信息
  const originalDesc = event.getDescription() || '';
  const updatedDesc = `${originalDesc}\n本周主讲人:${currentSpeaker}`;
  event.setDescription(updatedDesc);
}
  • 设置定时触发:点击左侧菜单栏的「触发器」图标,添加新触发器,选择updateWeeklySpeaker函数,触发类型选「时间驱动」,频率设为「每周」,指定每周更新的具体时间(比如周一凌晨)

2. Python脚本 + Google Calendar API(适合熟悉Python的场景)

如果更习惯用Python实现,可以结合谷歌日历API完成:

  • 先在Google云平台启用Google Calendar API,创建服务账号并下载密钥JSON文件
  • 安装依赖库:
pip install google-api-python-client google-auth-httplib2 google-auth-oauthlib
  • 编写Python脚本(基于你的原有逻辑修正并添加API调用):
import datetime
from googleapiclient.discovery import build
from google.oauth2 import service_account

# 配置信息
SPEAKERS = ['Person 1', 'Person 2', 'Person 3']
EVENT_ID = '替换为你的事件ID'
SERVICE_ACCOUNT_FILE = '你的服务账号密钥文件路径.json'
SCOPES = ['https://www.googleapis.com/auth/calendar']

# 初始化日历服务
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE, scopes=SCOPES
)
service = build('calendar', 'v3', credentials=credentials)

# 计算本周主讲人(修正原代码中week_of_year未定义的问题)
year, week, _ = datetime.date.today().isocalendar()
current_speaker = SPEAKERS[week % len(SPEAKERS)]

# 获取并更新事件描述
event = service.events().get(calendarId='primary', eventId=EVENT_ID).execute()
original_desc = event.get('description', '')
updated_desc = f"{original_desc}\n本周主讲人:{current_speaker}"

event['description'] = updated_desc
service.events().update(calendarId='primary', eventId=EVENT_ID, body=event).execute()

print(f"事件已更新,本周主讲人:{current_speaker}")
  • 设置定时任务:Windows用「任务计划程序」,Linux/macOS用cron,配置每周自动运行该脚本即可

内容的提问来源于stack exchange,提问作者A. Fenzry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 06:55:17