Skip to content

Instantly share code, notes, and snippets.

@jakevossen5
Created October 31, 2018 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakevossen5/ad022cab014ecbd0a30ee49782e9272c to your computer and use it in GitHub Desktop.
Save jakevossen5/ad022cab014ecbd0a30ee49782e9272c to your computer and use it in GitHub Desktop.
Percent done with hour/day/month
#!/usr/bin/env PYTHONIOENCODING=UTF-8 /usr/local/bin/python3
# To be used with bit-bar, which shows the % you are done with the current hour, day, week, and year
from datetime import datetime
now = datetime.now()
digits = 3
seconds_since_hour = (now - now.replace(minute=0, second=0, microsecond=0)).total_seconds()
print(("h" + ('{0:.2f}'.format(round((seconds_since_hour / 3600), digits)))[1:]), end= ' ')
seconds_since_midnight = (now - now.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds()
print("d" +('{0:.2f}'.format(round((seconds_since_midnight / 86400), digits)))[1:],end = ' ')
days_past_friday=(datetime.today().weekday() + 2) % 7
seconds_since_friday = days_past_friday * 86400 + seconds_since_midnight
#print(seconds_since_friday)
print("w" + ('{0:.2f}'.format(round((seconds_since_friday / 604800), digits)))[1:],end = ' ')
seconds_since_jan_1 = (now - now.replace(month = 1, hour=0, minute=0, second=0, microsecond=0)).total_seconds()
print("y" +('{0:.2f}'.format(round((seconds_since_jan_1 / (31540000)), digits)))[1:],end = ' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment