Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.