Skip to content

Instantly share code, notes, and snippets.

@GadgetSteve
Created December 29, 2018 08:44
Show Gist options
  • Save GadgetSteve/23eea518f370afd2b0e6fb9d5021f423 to your computer and use it in GitHub Desktop.
Save GadgetSteve/23eea518f370afd2b0e6fb9d5021f423 to your computer and use it in GitHub Desktop.
Python 2 countdown prompt
#!/usr/bin/env python
# encoding utf-8
"""
If you set your PYTHONSTARTUP environment variable to point to this file
with an absolute path then it will change your python 2 prompt to countdown
to the End Of Life of Python 2.
Copyright Steve Barnes <GadgetSteve@hotmail.com> 2017
License: Creative Commons
"""
from __future__ import print_function
import sys
import datetime
EOL = datetime.datetime(2020, 1, 1, 0, 0, 0, 0)
class timetoeol():
""" Class to give the time to end of life """
def __init__(self):
pass
def __str__(self):
""" Time to the EOL as a string."""
now = datetime.datetime.now()
if now < EOL:
result = "Py2 EOL in %s> " % (EOL-now)
else:
result = "RIPy2 %s ago> " % (now - EOL)
return result
TTEOL = timetoeol()
if sys.version_info.major < 3: # We don't need to do anything if running 3
if sys.version_info.minor < 7:
sys.ps1 = "OBSOLETE PY>"
else:
sys.ps1 = TTEOL
sys.ps2 = '.+. '
print('Python 2', str(TTEOL)[:-2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment