Skip to content

Instantly share code, notes, and snippets.

@jedberg
Last active February 26, 2017 23:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jedberg/61b2587b298af92adc5f985b11a20642 to your computer and use it in GitHub Desktop.
Save jedberg/61b2587b298af92adc5f985b11a20642 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from datetime import datetime as dt
from datetime import timedelta as td
from calendar import monthrange
import calendar
def make_bar(r):
return (int(round(r/10))*"*").ljust(10,'O')
# Put your birthday here
birth_year = 1970
birth_month = 1
birth_day = 1
birthday = dt(birth_year, birth_month, birth_day)
next_birthday_year = dt.now().year
if dt(dt.now().year,birth_month,birth_day) < dt.today().replace(hour=0, minute=0, second=0, microsecond=0):
next_birthday_year = dt.now().year + 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 a 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()
seconds_between_last_birthday_and_this_one = (dt(next_birthday_year, birth_month, birth_day) - dt(next_birthday_year - 1, birth_month, birth_day)).total_seconds()
# These are how many seconds are left as of right now
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()
seconds_left_till_birthday = (dt(next_birthday_year,birth_month, birth_day) - dt.now()).total_seconds()
# This actually prints the results
print("%25s %s" % ("Current time", str(dt.now())))
r = (seconds_left_in_day/seconds_in_day)*100
print("%25s %8.4f%% %-10s" % ("Day remaining", r, make_bar(r)))
r = (seconds_left_in_month/seconds_in_month)*100
print("%25s %8.4f%% %-10s" % ("Month remaining", r, make_bar(r)))
r = (seconds_left_till_birthday/seconds_between_last_birthday_and_this_one)*100
if dt(dt.now().year,birth_month,birth_day) == dt.today().replace(hour=0, minute=0, second=0, microsecond=0):
print("%25s %8.4f%% %-10s" % ("It's your birthday!!", 100.00, "**********"))
else:
print("%25s %8.4f%% %-10s" % ("Last birthday to next", r, make_bar(r)))
r = (seconds_left_in_year/seconds_in_year)*100
print("%25s %8.4f%% %-10s" % ("Year remaining", r, make_bar(r)))
r = (seconds_left_in_life/seconds_in_life)*100
print("%25s %8.4f%% %-10s" % ("Life remaining", r, make_bar(r)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment