Last active
February 15, 2019 02:19
-
-
Save jersey99/f2e2d5d6e4e3bf996e787156d884ac62 to your computer and use it in GitHub Desktop.
Get your age in seconds. And find out when you hit that integer exponent in your favorite base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import math | |
from datetime import datetime, timezone, timedelta | |
def get_tob_from_str(tob_str): | |
# Time of birth | |
try: | |
tob = datetime.strptime(tob_str, "%Y-%m-%dT%H:%M:%S%z") | |
except ValueError: | |
print('illegal format') | |
exit(1) | |
x = datetime.now(timezone.utc) - tob | |
print("You are currently {:,} seconds old".format(int(x.total_seconds()))) | |
return tob | |
def print_fun(tob, base, exponents): | |
for ex in exponents: | |
try: | |
dt = tob + timedelta(seconds=base**ex) | |
except OverflowError: | |
exit() | |
if dt > datetime.now(timezone.utc): | |
print('You will be {}^{:2d} seconds old at {}'.format(base, ex, dt)) | |
else: | |
print('You were {}^{:02d} seconds old at {}'.format(base, ex, dt)) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Get your age in seconds. And' | |
' find out when you hit that integer' | |
' exponent in your favorite base') | |
parser.add_argument('-t', '--tob_str', help='1987-05-31T06:45:00+0530', | |
default='1987-05-31T06:45:00+0530') | |
parser.add_argument('-b', '--base', help='base', default=math.e) | |
args = parser.parse_args() | |
tob = get_tob_from_str(args.tob_str) | |
exponents = range(0, 50, 1) | |
if args.base in ['E', 'e']: | |
base = math.e | |
elif args.base in ['pi', 'PI', 'Pi']: | |
base = math.pi | |
elif args.base in ['tau', 'TAU', 'Tau']: | |
base = math.tau | |
else: | |
base = float(args.base) | |
if base in [1, 1.0]: | |
exit() | |
if int(base) == base: | |
base = int(base) | |
print_fun(tob, base, exponents) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try Julian Days