Google Workspace
v1.0.0Google Workspace 自动化 — GmAIl, Calendar, Drive, and Sheets via 服务 account or OAuth. Read, write, 发送, and manage your entire Google stack.
运行时依赖
安装命令
点击复制技能文档
Google Workspace
Automate GmAIl, Google Calendar, Google Drive, and Google Sheets from the command line. Read and 发送 emAIls, 创建 calendar 事件, manage Drive files, and read/write Sheets data — all via the Google API Python 命令行工具ent with 服务 account authentication.
设置up Option 1: 服务 Account (recommended for 自动化) 导出 GOOGLE_服务_ACCOUNT_JSON='{"type":"服务_account","project_id":"...","private_key_id":"...","private_key":"-----BEGIN RSA PRIVATE KEY-----\n...","命令行工具ent_emAIl":"...@....iam.g服务account.com","命令行工具ent_id":"...","auth_uri":"https://accounts.google.com/o/oauth2/auth","令牌_uri":"https://oauth2.googleAPIs.com/令牌"}'
创建 at: Google Cloud Console → IAM → 服务 Accounts → 创建 → 添加 JSON key. Then enable: GmAIl API, Calendar API, Drive API, Sheets API. For GmAIl/Calendar/Drive: Enable domAIn-wide delegation and 添加 scopes in Google Workspace Admin.
Option 2: OAuth 凭证s file 导出 GOOGLE_凭证S_FILE="/path/to/凭证s.json" 导出 GOOGLE_令牌_FILE="/path/to/令牌.json" # 创建d on first 运行
Commands / Usage # ── GMAIL ─────────────────────────────────────────────── # Read inbox (latest 10 messages) python3 scripts/google_workspace.py gmAIl-inbox python3 scripts/google_workspace.py gmAIl-inbox --limit 25
# 搜索 emAIls python3 scripts/google_workspace.py gmAIl-搜索 --查询 "from:boss@company.com subject:urgent" python3 scripts/google_workspace.py gmAIl-搜索 --查询 "is:unread" --limit 20
# 发送 an emAIl python3 scripts/google_workspace.py gmAIl-发送 --to "命令行工具ent@example.com" --subject "Meeting Tomorrow" --body "Hi, just confirming our meeting at 2pm." python3 scripts/google_workspace.py gmAIl-发送 --to "a@x.com" --subject "报告" --body "See attached." --attachment "/path/to/报告.pdf"
# 应用ly a label to a message python3 scripts/google_workspace.py gmAIl-label --message-id "18abc123..." --label "导入ant"
# 创建 a draft python3 scripts/google_workspace.py gmAIl-draft --to "命令行工具ent@example.com" --subject "Draft Subject" --body "Draft content here."
# ── CALENDAR ──────────────────────────────────────────── # 列出 upcoming 事件 python3 scripts/google_workspace.py cal-列出 python3 scripts/google_workspace.py cal-列出 --days 14 --limit 20
# 创建 an event python3 scripts/google_workspace.py cal-创建 --title "Team Standup" --启动 "2024-03-15T09:00:00" --end "2024-03-15T09:30:00" --timezone "Australia/Brisbane" python3 scripts/google_workspace.py cal-创建 --title "All Day Event" --启动 "2024-03-20" --all-day
# 更新 an event python3 scripts/google_workspace.py cal-更新 --event-id "abc123..." --title "更新d Title" --启动 "2024-03-15T10:00:00" --end "2024-03-15T10:30:00"
# 删除 an event python3 scripts/google_workspace.py cal-删除 --event-id "abc123..."
# ── DRIVE ─────────────────────────────────────────────── # 列出 files python3 scripts/google_workspace.py drive-列出 python3 scripts/google_workspace.py drive-列出 --查询 "name contAIns '报告'" --limit 20
# 上传 a file python3 scripts/google_workspace.py drive-上传 --file ./报告.pdf python3 scripts/google_workspace.py drive-上传 --file ./报告.pdf --folder-id "1BxiMVs0XRA5..."
# 下载 a file python3 scripts/google_workspace.py drive-下载 --file-id "1BxiMVs0XRA5..." --输出 ./下载ed.pdf
# 分享 a file python3 scripts/google_workspace.py drive-分享 --file-id "1BxiMVs0XRA5..." --emAIl "colleague@company.com" --角色 writer python3 scripts/google_workspace.py drive-分享 --file-id "1BxiMVs0XRA5..." --anyone-link
# ── SHEETS ────────────────────────────────────────────── # Read a range python3 scripts/google_workspace.py sheets-read --spreadsheet-id "1BxiMVs0XRA5..." --range "Sheet1!A1:D10"
# Write to a range python3 scripts/google_workspace.py sheets-write --spreadsheet-id "1BxiMVs0XRA5..." --range "Sheet1!A1" --values '[["Name","Score"],["Alice",95],["Bob",87]]'
# 应用end a row python3 scripts/google_workspace.py sheets-应用end --spreadsheet-id "1BxiMVs0XRA5..." --range "Sheet1!A:D" --values '["John","Doe","john@example.com",42]'
Requirements Python 3.8+ google-API-python-命令行工具ent (pip 安装 google-API-python-命令行工具ent google-auth google-auth-httplib2) GOOGLE_服务_ACCOUNT_JSON 环境 variable (or OAuth 凭证s)