Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
from datetime import datetime as dt
from datetime import timedelta as td
from calendar import monthrange
import calendar
# Put your birthday here
birthday = dt(1970, 1, 1)
# Put your death day here
# There are lots of great life expectancy calculators out there:
# https://www.google.com/search?q=calculate+your+lifespan
deathday = dt(2060, 1, 1)
# These calculate how many seconds are in each time period. They aren't always static amount due to leap seconds and years and differing month lengths.
seconds_in_day = ((dt(dt.now().year, dt.now().month, dt.now().day) + td(days=1)) - (dt(dt.now().year, dt.now().month, dt.now().day))).total_seconds()
seconds_in_month = ((dt(dt.now().year, dt.now().month, monthrange(dt.now().year, dt.now().month)[1]) + td(days=1)) - (dt(dt.now().year, dt.now().month, 1))).total_seconds()
seconds_in_year = ((dt(dt.now().year,1,1) + td(days=(365 + calendar.isleap(dt.now().year)))) - (dt(dt.now().year, 1, 1))).total_seconds()
seconds_in_life = (deathday - birthday).total_seconds()
# These are how many seconds are left today
seconds_left_in_day = (((dt(dt.now().year, dt.now().month, dt.now().day) + td(days=1))) - dt.now()).total_seconds()
seconds_left_in_month = ((dt(dt.now().year, dt.now().month, monthrange(dt.now().year, dt.now().month)[1]) + td(days=1)) - dt.now()).total_seconds()
seconds_left_in_year = ((dt(dt.now().year,1,1) + td(days=(365 + calendar.isleap(dt.now().year)))) - dt.now()).total_seconds()
seconds_left_in_life = (deathday - dt.now()).total_seconds()
# This actually prints the results
print("%20s %s" % ("Current time", str(dt.now())))
r = (seconds_left_in_day/seconds_in_day)*100
print("%20s %2.4f%% %-10s" % ("Day remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
r = (seconds_left_in_month/seconds_in_month)*100
print("%20s %2.4f%% %-10s" % ("Month remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
r = (seconds_left_in_year/seconds_in_year)*100
print("%20s %2.4f%% %-10s" % ("Year remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
r = (seconds_left_in_life/seconds_in_life)*100
print("%20s %2.4f%% %-10s" % ("Life remaining", r, (int(round(r/10))*"*").ljust(10,'O')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment