Created
February 19, 2020 01:27
-
-
Save SlyCodePanda/72b0ee52c99dd675d8e235748ae5f363 to your computer and use it in GitHub Desktop.
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
''' | |
Code that lets you create a countdown to a certian date and time. | |
''' | |
#!/usr/bin/python | |
from datetime import datetime, time | |
class bcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
def dateDiffInSec(date1, date2): | |
timedelta = date2 - date1 | |
return timedelta.days * 24 * 3600 + timedelta.seconds | |
def daysHoursMinutesSecondsFromSeconds(seconds): | |
minutes, seconds = divmod(seconds, 60) | |
hours, minutes = divmod(minutes, 60) | |
days, hours = divmod(hours, 24) | |
return (days, hours, minutes, seconds) | |
# Example of use. | |
todayDate = datetime.now() | |
endDate = datetime.strptime('2020-06-14', '%Y-%m-%d') | |
days, hrs, mins, secs = daysHoursMinutesSecondsFromSeconds(dateDiffInSec | |
(todayDate, endDate)) | |
if days == 30: | |
print bcolors.WARNING + "Your contract ends in a month from today..." + \ | |
bcolors.ENDC | |
elif days < 30: | |
print bcolors.WARNING + "Your contract ends in less than a month" | |
print "%d days left." % days + bcolors.ENDC | |
elif days == 0: | |
print bcolors.FAIL + "Current contract finishes today" + bcolors.ENDC | |
else: | |
print bcolors.OKGREEN + "You have %d days until your " \ | |
"current contract ends." % days + bcolors.ENDC | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment