This project monitors changes in Google Sheets and Google Docs using a Python script triggered by a Go-based cron scheduler every 5 minutes. If any changes are detected in the specified range or document, they are logged locally.
Ideal for automation, internal dashboards, and passive document monitoring.
- β° A Go cron scheduler (
robfig/cron/v3) runs every 5 minutes. - π It triggers
fetch_google_sheets_docs.py, a Python script that:- Reads data from a Google Sheet (via Google Sheets API)
- Checks revision ID of a Google Doc (via Google Docs API)
- π§ Compares data with the last known state stored in:
sheet_hash.json(for Sheets)doc_last_modified.json(for Docs)
- π Logs messages when updates are detected.
| Tech | Usage |
|---|---|
| Python | Google API integration logic |
| Go | Cron scheduler |
| JSON | For tracking previous state |
| Google APIs | Sheets & Docs integration |
cron-job-service/
βββ cron_job/
β βββ cron_job.go # Go cron scheduler
β βββ fetch_google_sheets_docs.py # Python logic
β βββ requirements.txt # Python dependencies
β βββ doc_last_modified.json # Stores last Google Doc revision ID
β βββ sheet_hash.json # Stores Google Sheet hash
β βββ fetch_google_sheets_docs.log # Optional log file
β βββ credentials/
β βββ credentials.json # Google service account key (ignored by Git)
βββ README.md
βββ .gitignore
βββ commands.txt
- Python 3.x
- Go 1.16 or later
- Git
- Google Cloud project with:
- Sheets API and Docs API enabled
- A service account key in JSON format
git clone https://github.com/Chat-craft/Cron-job.git
cd Cron-jobcd cron_job
python -m venv venv
venv\Scripts\activate # (Windows)
# OR
source venv/bin/activate # On Linux/Mac
pip install -r requirements.txtβ (Optional) Test the Python script:
python fetch_google_sheets_docs.pyIf needed, set your GOPATH to a user-friendly location (especially on Windows):
$env:GOPATH="C:\Users\Checkout\go"Install cron dependency and run the Go scheduler:
go get github.com/robfig/cron/v3
go run cron_job.go- Go to Google Cloud Console
- Create or select a project
- Enable:
- Google Sheets API
- Google Docs API
- Generate a service account and download the
credentials.json - Save the file as:
cron_job/credentials/credentials.json
Basic unit tests are available in:
cron_job/tests/test_fetch_google_sheets_docs.py
Run them with:
python -m unittest cron_job.tests.test_fetch_google_sheets_docs