Skip to content

Chat-craft/Cron-job

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ•’ Cron-Job: Google Sheets & Docs Change Monitor

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.


πŸ”§ What It Does

  • ⏰ 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 Stack

Tech Usage
Python Google API integration logic
Go Cron scheduler
JSON For tracking previous state
Google APIs Sheets & Docs integration

πŸ“ Project Structure

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

πŸ›  Prerequisites

  • 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

πŸš€ Setup Instructions

1. Clone the Repository

git clone https://github.com/Chat-craft/Cron-job.git
cd Cron-job

2. Set up Python

cd 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.py

3. Set up Go Environment

If 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

πŸ” Google Cloud Setup

  1. Go to Google Cloud Console
  2. Create or select a project
  3. Enable:
    • Google Sheets API
    • Google Docs API
  4. Generate a service account and download the credentials.json
  5. Save the file as:
    cron_job/credentials/credentials.json
    

πŸ§ͺ Tests

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published