DEV Community

Cover image for Building My First Python CLI Tool: A Simple Day Counter to Track Time
Adam Malsagov
Adam Malsagov

Posted on • Edited on

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

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!

Top comments (2)

Collapse
 
ramoyald profile image
IO_Node

I'm working on something similar in python to built a loading bar for functions that take a long time to execute. I'm new here, happy to meet new people. We appear to be around the same skill level, I just finished creating similar stuff earlier this week.

Collapse
 
adam_dev profile image
Adam Malsagov • Edited

Hey man nice to meet you too, and good luck with your project! I look forward to seeing how it goes and reading your updates on DEV