Created
April 11, 2024 16:20
-
-
Save Teque5/74e0372cce5d7d06bd773b034379a1ca to your computer and use it in GitHub Desktop.
UNIX Epoch Countdown Script
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 | |
""" | |
UNIX Epoch Countdown | |
Originally written for 1.7e9 epoch by Teque5 | |
November, 2023 | |
""" | |
import time | |
import numpy as np | |
import seaborn as sns | |
from matplotlib import cm, colors | |
end = 1.8e9 | |
mod = 10 | |
boldmod = 10 | |
rgba255 = np.zeros(4) | |
CSI = "\033" | |
spins = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏" | |
cmap = sns.husl_palette(as_cmap=True) | |
# https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color | |
# thresh = np.array([0.299, 0.587, 0.114, 0]) | |
def wrap_color(a_string, rgba255=(255, 0, 0, 0), is_bold=False): | |
# bgstart = CSI+'[40m' if (rgba255 * thresh).sum() < 186 else CSI+'[47m' | |
boldstart = CSI + "[1m" if is_bold else "" | |
boldstop = CSI + "[0m" if is_bold else "" | |
reset = CSI + "[0m" | |
return f"{boldstart}{CSI}[38;2;{rgba255[0]:.0f};{rgba255[1]:.0f};{rgba255[2]:.0f}m{a_string}{boldstop}{reset}" | |
while True: | |
try: | |
now = time.time() | |
remaining = end - now | |
rgba255[:] = cmap((remaining % mod) / mod) | |
rgba255 *= 255 | |
is_bold = (remaining % boldmod) < 1 | |
spindx = int(remaining * 10 % mod) | |
spin = "✯" if remaining < 0 else spins[spindx] | |
print("Celebration " + wrap_color(f"{end:>14.3f} {spin}", rgba255, is_bold)) | |
print("Currently " + wrap_color(f"{now:>14.3f}", rgba255, is_bold)) | |
print("Remaining " + wrap_color(f"{remaining:>14.3f}", rgba255, is_bold)) | |
print(f"{CSI}[3A", end="") # move up 3 lines | |
# time.sleep(.01) | |
except KeyboardInterrupt: | |
print(f"{CSI}[39;49m{CSI}[0m\n\n\n") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ./countdown.py