-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgetCurrentDayOfWeekInPython.py
More file actions
61 lines (40 loc) · 1.8 KB
/
getCurrentDayOfWeekInPython.py
File metadata and controls
61 lines (40 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/python
# get current day of week in Python
import colorama, os, sys, time, traceback
from colorama import Fore, Style
from datetime import datetime
colorama.init()
def checkOs():
print("Started checking operating system at", datetime.now().strftime("%m-%d-%Y %I:%M %p"))
if sys.platform == "win32":
print(Fore.GREEN + "Operating System:", end=""); sys.stdout.flush()
os.system('ver')
print(Style.RESET_ALL, end="")
elif sys.platform == "darwin":
print(Fore.GREEN + "Operating System: ")
os.system('sw_vers')
print(Style.RESET_ALL, end="")
elif sys.platform == "linux":
print(Fore.GREEN + "Operating System: ")
os.system('sw_vers')
print(Style.RESET_ALL, end="")
print("Finished checking operating system at", datetime.now().strftime("%m-%d-%Y %I:%M %p"))
print("")
def getCurrentDayOfWeek():
print("\nGet current day of the week in Python.\n")
try:
checkOs()
startDateTime = datetime.now()
print("Started getting current day of the week at", startDateTime.strftime("%m-%d-%Y %I:%M %p"))
print(Fore.BLUE + "The current day of the week is: {0}.".format(time.strftime('%A')))
print(Fore.GREEN + "Successfully got the current day of the week." + Style.RESET_ALL)
finishedDateTime = datetime.now()
print("Finished getting current day of the week at", finishedDateTime.strftime("%m-%d-%Y %I:%M %p"))
duration = finishedDateTime - startDateTime
print("Total execution time: {0} second(s)".format(duration.seconds))
print("")
except Exception:
print(Fore.RED + "Failed to get current day of the week.")
traceback.print_exc()
exit("" + Style.RESET_ALL)
getCurrentDayOfWeek()