Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Run a Python script on a schedule for free and write the results to Google Sheets (GitHub Actions + gspread)

说明与用途

使用 GitHub Actions、Google 服务账号和 gspread 自动每天运行 Python 脚本,从 Open‑Meteo 获取天气并将行追加到 Google 表格。

问题

Run a Python script that fetches data every morning and store the result in a Google Sheet without renting a server or keeping a laptop on.

结果

The workflow runs daily, logs yesterday’s weather to the sheet, and avoids duplicate entries.

工作流

  • Create a Google Cloud project and enable the Sheets API.
  • Create a service account, download its JSON key, and keep it secret.
  • Share the target Google Sheet with the service account email as Editor and note the Sheet ID.
  • Create a repository with requirements.txt (gspread>=6,<7 requests>=2.28) and job.py containing the fetch and write logic.
  • Add a GitHub Actions workflow that sets secrets GOOGLE_SA_JSON and SHEET_ID, runs job.py on a cron schedule.
  • The script checks if the date exists in column A; if not, it appends the new row.
  • The workflow logs success or skips if the row already exists.

证据

GitHub Actions runs the script on a cron schedule.

来源

A service account is a robot Google identity with its own e‑mail address.

来源

gspread writes the row.

来源

  • 记录日期: 2026-11-01T14:59:38.406Z