Skip to main content

A thread-safe, persistent, dual-mode CLI Alarm Clock

Project description

⏰ Command-Line Interface (CLI) Alarm Clock

A professional, robust, and zero-dependency Command-Line Interface (CLI) Alarm Clock written in Python. It runs natively and works seamlessly on both Windows and Linux.

Designed with Clean Architecture and Unix-style CLI daemon patterns, the application supports:

  1. Interactive Shell Mode: A fully interactive console screen with a live ticking clock header and dynamic command prompt.
  2. Daemon Mode: Run the background sound and time monitor (alarm-clock daemon).
  3. OS-Native Task Mode (Zero Manual Daemon): Alarms automatically register with the operating system scheduler (Windows Task Scheduler via schtasks or Linux via crontab). When the time is reached, the OS automatically pops up a terminal instance to play sound and accept user inputs.

✨ Features

  • Global CLI command integration: Can be installed and executed globally as alarm-clock in the system shell.
  • Dual Sound Alert Modes:
    • Background Python daemon checks system time and plays sound.
    • OS-native schedulers trigger short-lived processes to ring.
  • OS-Native Task Automation:
    • Windows: Creates user-level tasks using schtasks with automatic date fallback mechanisms for locale compatibility (dd/mm/yyyy vs mm/dd/yyyy).
    • Linux: Appends entries programmatically to the user's crontab.
  • Atomic File Writing: Prevents state corruption by writing changes to a temporary file before atomically swapping it with the target database file (~/.cli_alarms.json).
  • Thread-Safe Memory Lock: Synchronizes all database reads and writes under a shared mutex lock to isolate background checks from user adjustments.
  • Automatic Encoding Fallback: Prevents crashes on legacy Windows cmd consoles that default to non-Unicode codepages (e.g., CP1252) by automatically replacing emojis with safe fallback indicators.
  • Cross-Platform Audio alerts:
    • Windows: Uses native winsound.Beep.
    • Linux/macOS: Uses terminal buzzer beeps (\a).
  • Flexible Alarm Operations: add, list, remove, snooze, and dismiss.
    • Supports setting an alarm-specific default snooze limit (--snooze-minutes) which is automatically respected if no snooze duration is entered during rings.

🛠️ Architecture & Design Decisions

               ┌───────────────────────┐
               │    Local CLI Shell    │
               │ (Direct Single-Cmds)  │
               └───────────┬───────────┘
                           │ Writes/Reads
                           ▼
               ┌───────────────────────┐
               │  ~/.cli_alarms.json   │◄─── (Atomic State DB)
               └───────────────────────┘
                           ▲
                           │ Reads/Updates State
                           ▼
 ┌───────────────────────────────────────────────────────────┐
 │                   Background Daemon Mode                  │
 │                                                           │
 │  ┌───────────────────────┐       ┌─────────────────────┐  │
 │  │   Scheduler Thread    ├──────►│ Sound Loop Thread   │  │
 │  │ (Monitors System Time)│       │ (Non-blocking Beep) │  │
 │  └───────────────────────┘       └─────────────────────┘  │
 └───────────────────────────────────────────────────────────┘
                           ▲
                           │ Triggers Subprocess Ring Command
                           ▼
 ┌───────────────────────────────────────────────────────────┐
 │                  OS-Scheduled Task Mode                   │
 │                                                           │
 │  ┌────────────────────────┐       ┌────────────────────┐  │
 │  │ Windows Task Scheduler ├──────►│ alarm-clock ring   │  │
 │  │       / Linux Cron     │       │ (Terminal Pop-Up)  │  │
 │  └────────────────────────┘       └────────────────────┘  │
 └───────────────────────────────────────────────────────────┘

🚀 Getting Started

1. Installation

To register the alarm-clock terminal command, install the package locally from the root workspace directory.

On Windows (without requiring admin privileges):

pip install --user -e .

Note: Make sure your user script folder (e.g. C:\Users\<username>\AppData\Roaming\Python\Python312\Scripts) is in your system's PATH. If it's not, you can run the executable directly by targeting its path, or use python -m alarm_clock.cli.

On Linux / macOS:

pip install -e .

2. Running Unit Tests

A comprehensive test suite is included in /tests covering the parser, models, scheduler, serialization, persistence, and OS scheduler triggers. Run it with:

python -m unittest discover -s tests

🕹️ Command Reference

Option A: OS-Native Mode (Recommended - Zero Manual Daemon)

When you add an alarm, it is registered automatically with the operating system.

  1. Add an alarm:
    alarm-clock add 07:30 "Wake Up" --snooze-minutes 8 --auto-dismiss 30
    
  2. List alarms:
    alarm-clock list
    
  3. When the time is reached, the operating system launches a terminal window automatically, starts beep-beeping, and prompts you:
    Press Enter to dismiss, or type 'snooze' to snooze:
    
    If you type snooze, it automatically snoozes for 8 minutes (respecting the custom snooze parameter).
  4. Remove an alarm (cleans it up from both disk and OS task registries):
    alarm-clock remove 1
    

Option B: Daemon Mode (Manual Persistent Process)

  1. Start the monitor daemon (run this in a separate terminal window or pane to play sound when alarms go off):
    alarm-clock daemon
    
  2. Snooze/Dismiss from your main terminal:
    alarm-clock snooze 1 10
    alarm-clock dismiss 1
    

Option C: Interactive Shell Mode

If you run alarm-clock without any arguments, it launches a persistent, interactive console session. It manages its own background timing thread and audio loops automatically in a single terminal.

alarm-clock

Inside the interactive session, the prompt updates live and you can type sub-commands like add, list, snooze, dismiss, and exit directly:

(22:15:30) alarm-clock > add 07:30 Morning Workout
Success: Created Alarm 1 for 07:30 ('Morning Workout')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alarmy_cli-1.0.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alarmy_cli-1.0.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file alarmy_cli-1.0.1.tar.gz.

File metadata

  • Download URL: alarmy_cli-1.0.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for alarmy_cli-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f9dc09e07eae19a93207112966f1c85c29e184ad65baf0d8bc093ba6a8effaa9
MD5 91510335c5e602bd828e81c8b7890726
BLAKE2b-256 7bb5d774734b935c7ab88b2e945ccffa2bd4ffe058989ec01d1e7ac8a0dca9fd

See more details on using hashes here.

File details

Details for the file alarmy_cli-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: alarmy_cli-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for alarmy_cli-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69a76e230ded3832cb9048c3d46ee422eaaf5f53f472cd638e19c5f68985e247
MD5 a29188e40615b34c530f81c7ee70fc0f
BLAKE2b-256 1c868a5395d795ba518682b1c57072664e4146d269854fe103b26554fbec568e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page