DEV Community

David García
David García

Posted on

Python script to track employee work hours without buying software

```html

Let’s be honest. Tracking employee work hours shouldn’t involve complicated payroll systems or expensive software. As developers, we’re comfortable building solutions, and a simple Python script can handle this surprisingly well. This isn't about creating a fancy HR tool; it’s about getting a reliable record of time spent on projects.

The Problem: Manual Time Sheets are a Pain

We've all been there. Employees filling out paper time sheets, discrepancies, arguing about “focused work” time, and a whole lot of admin overhead. Existing time tracking software often feels like overkill – especially for smaller teams or freelancers. Plus, integrating those systems with existing workflows can be a nightmare. The goal here is a straightforward, automated solution that gives you the data you need, without the extra complexity.

A Simple Python Script for Tracking Hours

Here's a basic Python script to track employee work hours. It’s designed to be easily extended and integrated into your workflow. This isn't production-ready code, but a solid foundation for a simple tracking system.


import datetime

def record_time():

name = input("Enter employee name: ")

start_time = datetime.datetime.now()

print(f"Start time recorded for {name}: {start_time}")

In a real application, you'd save this to a file or database.

def main():

while True:

record_time()

choice = input("Record another employee's time? (y/n): ")

if choice.lower() != 'y':

break

if name == "main":

main()

Let’s break down the key parts:

  • import datetime: Imports the `datetime` module for working with dates and times.
  • datetime.datetime.now(): Gets the current date and time.
  • input(): Prompts the user for employee information.
  • The `while` loop allows you to record multiple employee times.

Practical Results & Next Steps

Running this script will prompt you for an employee’s name and record the timestamp. You can then record multiple employees' times. This is a starting point. To make this truly useful, you’d want to:

  • Save the data to a file (CSV, JSON) or a simple database (SQLite).
  • Add error handling (what if the user enters invalid input?).
  • Implement a way to stop the timer.

Conclusion & Let’s Talk Automation

Tracking work hours doesn’t have to be a tedious chore. This simple Python script demonstrates how automation can streamline a surprisingly common task. If you’re looking for more robust solutions for time tracking, process automation, or need help integrating these types of tools into your existing infrastructure, I’d be happy to chat. I specialize in building custom solutions to optimize workflows and boost productivity.

Learn more about my services and how I can help you build smarter automation at https://itelnetconsulting.com/.

```


Itelnet Consulting

Top comments (0)