Skip to content

Instantly share code, notes, and snippets.

@kism
Last active April 12, 2024 14:38
Show Gist options
  • Save kism/e7b743cfba3edc56963154e3eebfe436 to your computer and use it in GitHub Desktop.
Save kism/e7b743cfba3edc56963154e3eebfe436 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import subprocess
import sys
from datetime import datetime
# Define the command
command = "git log --format='%at'"
# Run the command
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode != 0:
# Print the error message if the command failed
print("Error:", result.stderr)
sys.exit(1)
nworkdays = 0
nfreedays = 0
committimes = []
for i in result.stdout.split('\n'):
i = i.strip()
if i != "":
committimes.append(int(i))
for unix_time in committimes:
# Convert Unix timestamp to datetime object
dt = datetime.fromtimestamp(unix_time)
# Check if it's a weekday (Monday=0, Sunday=6)
if dt.weekday() < 5 and 8 <= dt.hour < 17:
nworkdays = nworkdays + 1
else:
nfreedays = nfreedays + 1
totalcommits = nfreedays + nworkdays
print("Total commits: " + str(totalcommits))
print("Commits during free time:" + str(nfreedays))
result = nfreedays / totalcommits * 100
print("Percent during free time:" + str(round(result)) + "%")
print("Commits during work time:" + str(nworkdays))
result = nworkdays / totalcommits * 100
print("Percent during work time:" + str(round(result)) + "%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment