Building My First Python CLI Tool: A Simple Day Counter to Track Time

A

Adam Malsagov

Guest
Hello DEV community! πŸ‘‹

I recently started working on personal projects, writing small scripts and sharing them on GitHub. Before that, I mostly followed tutorials and read programming books, but building my own projects helped me learn faster and grasp concepts more deeply. As the next step in my learning journey, I developed my first command-line interface (CLI) tool, Day Counter, which I’m excited to share.

What is Day Counter?​


Day Counter is a lightweight CLI tool in Python that tracks time in days, hours, and minutes since a specific event. The program stores time in a JSON file and displays the elapsed time. I started with a simple script and expanded it into a CLI tool to deepen my understanding of command-line applications.

Features​

  • Command-line arguments:
    • --view: Check the current time elapsed since the event.
    • --reset: Reset or initialize the counter.
  • Persistent data storage:
    • Saves the timestamp data to a JSON file, so your counter keeps track even after closing the program.

How It Works​


Using Day Counter is straightforward. To start tracking time since an event, run:

python day_counter.py --reset

to start or reset the counter. You can check the counter anytime with:

python day_counter.py --view

to see how much time has passed.

Day Counter CLI showing --reset and --view commands in terminal Example of running the Day Counter CLI tool

Conclusion​


Day Counter is a simple CLI tool that introduced me to command-line applications. It provided a solid foundation for creating more advanced CLI tools in the future, with more command line arguments and the use of third-party libraries.

GitHub Repository​


If you want to try it out or check out the code, here’s the repository: https://github.com/adam-malsagov/day-counter-cli

Thanks for reading!

Continue reading...
 


Join 𝕋𝕄𝕋 on Telegram
Channel PREVIEW:
Back
Top