Thanks to visit codestin.com
Credit goes to github.com

Skip to content

kudadonbe/iclock-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

iClock-Sync

iClock-Sync is a Python-based tool designed to fetch and upload attendance logs from ZKTeco iClock devices directly to Google Firestore. It integrates seamlessly with school management systems like SchoolSync and is built modularly, ensuring flexibility for future expansions to support databases such as MySQL, PostgreSQL, MongoDB, and more.


πŸš€ Features

  • πŸ”„ Multi-Device Support: Fetch attendance logs from multiple ZKTeco iClock devices.
  • 🩹 Structured Normalization: Logs are consistently formatted with unique IDs and comprehensive validation.
  • ☁️ Firestore Integration: Uploads only new, deduplicated records with smart caching.
  • πŸ’Ύ Local Audit Logs: Save uploaded logs locally for verification and auditing.
  • 🧠 High-Performance Caching: Smart cache management using uploaded_ids_cache.json (99%+ efficiency).
  • πŸ§ͺ Dry-Run Mode: Safely preview uploads without altering Firestore data.
  • ⏳ Smart Date Filtering: Efficiently filter logs to upload only recent records, reducing processing by 99%.
  • πŸ” Optimized Syncing: Intelligent sync intervals with built-in performance optimization.
  • πŸ›‘οΈ Data Validation: Comprehensive validation prevents invalid records from reaching Firestore.
  • πŸ”§ Command-Line Interface: Run using iclock --export-simple, --dry-run, etc. after editable install.

🧰 Installation & Setup

1. Clone the Repository

git clone https://github.com/kudadonbe/iclock-sync.git
cd iclock-sync

2. Create and Activate Virtual Environment

We recommend using a virtual environment based on your OS:

πŸ”Ή macOS / Linux

python3 -m venv .venv
source .venv/bin/activate

πŸ”Ή Windows (PowerShell)

python -m venv .venv
.venv\Scripts\Activate.ps1

⚠️ If activation fails, run this once:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

3. Install Dependencies

pip install -r requirements.txt

4. Editable Install for CLI Command (iclock)

pip install -e .

If using python -m cli, also set:

$env:PYTHONPATH = "$(Get-Location)"

5. Add Firebase Credentials

Place your Firebase Admin SDK credentials in:

config/firebase-key.json

6. Configure Your Settings

Update config/settings.py or use .env:

FIREBASE_KEY_PATH=config/firebase-key.json

πŸ“ Recommended Project Structure

iclock-sync/
β”œβ”€β”€ cache/                             # Cached data
β”‚   └── uploaded_ids_cache.json
β”œβ”€β”€ config/                            # Configuration files
β”‚   β”œβ”€β”€ firebase-key.json
β”‚   └── settings.py
β”œβ”€β”€ core/                              # Core application logic
β”‚   β”œβ”€β”€ firestore_uploader.py
β”‚   β”œβ”€β”€ iclock_connector.py
β”‚   β”œβ”€β”€ normalizer.py
β”‚   └── utils.py
β”œβ”€β”€ data/                              # Sample or test data
β”‚   β”œβ”€β”€ sample_logs.txt
β”œβ”€β”€ logs/                              # Application log files
β”‚   β”œβ”€β”€ sync_*.log
β”œβ”€β”€ output/                            # Output logs (JSON)
β”‚   β”œβ”€β”€ logs_*.json
β”œβ”€β”€ .env                               # Environment-specific variables
β”œβ”€β”€ .env.example                       # Template
β”œβ”€β”€ cli.py                             # Main CLI entry-point
β”œβ”€β”€ pyproject.toml                     # Project metadata
β”œβ”€β”€ requirements.txt                   # Python dependencies
└── README.md                          # Project documentation

βš™οΈ Usage

πŸš€ Sync Logs to Firestore

iclock

πŸ§ͺ Dry-Run (Preview Mode)

iclock --dry-run

⏳ Recent Logs Only

iclock --since 2

♻️ Periodic Sync (Looping)

iclock --loop 5 --since 1

⚑ Export Logs

iclock --export-simple
iclock --export-normalized

πŸš€ Combine Options

iclock --dry-run --since 1

Or directly:

python -m cli --dry-run --since 1

Use this if iclock command isn't recognized. Also set:

$env:PYTHONPATH = "$(Get-Location)"

πŸ” Environment and Secrets

  • Firebase credentials: firebase-key.json
  • Optional: .env file with FIREBASE_KEY_PATH

πŸ›‘οΈ Reliability and Safety

  • Idempotent uploads (no duplicates)
  • Audit trail via output logs
  • Handles multiple devices gracefully

πŸ’‘ Planned Future Improvements

  • MySQL, PostgreSQL, MongoDB support
  • Web dashboard
  • REST API layer via FastAPI

πŸ§‘β€πŸ’» Author

Hussain Shareef (@kudadonbe)
Makunudhoo School, Maldives πŸ‡²πŸ‡»


πŸ“„ License

MIT License β€” free for personal/commercial use


πŸ™ Acknowledgements

About

Sync iClock attendance logs to Firestore and other databases.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors