Skip to content

Instantly share code, notes, and snippets.

@NP-chaonay
Last active June 23, 2020 12:19
Show Gist options
  • Save NP-chaonay/b63c002b9337c60610bc8ec137296dc1 to your computer and use it in GitHub Desktop.
Save NP-chaonay/b63c002b9337c60610bc8ec137296dc1 to your computer and use it in GitHub Desktop.
My main stopwatch program written in Python.
#!/usr/bin/env python3
# Name: Main Stopwatch
# Description: My main stopwatch program written in Python.
# Author: Nuttapong Punpipat (NP-chaonay)
# Version: V.2.0.0_beta
# Revised Date: 2020-06-23 12:20 (UTC)
# License: MIT License
# Version Note:
# - Major version: indicates of very significant changes or changes that break compatibility on some system/platforms.
# - Minor version: indicates of significant changes or features adding.
# - Micro version: indicates of small changes or bug patches, or even typo revising.
# Programming Language: Python
# CUI/GUI Language: English
import time
start=time.time()
end=time.time()
# Multiply by 2 for 'start' and 'end' variables assignment latency
latency=2*(end-start)
import sys,np_chaonay_main
if len(sys.argv)>=2:
start=float(sys.argv[1])
start_ltime=list(map(str,time.localtime(start)))
print('Start Time (From UNIX Epoch) :',start)
print('Start Time (Based on Local Time) :',np_chaonay_main.display_datetime(start))
print('Latency:',latency)
msgs=['Seconds','Minutes','50-minutes period','90-minutes period','50-minutes Minute-Remainder','90-minutes Minute-Remainder']
divs=(50*60,90*60)
while True:
try:
print('Press Ctrl+C to view the result or stop the timer.',end='',flush=True)
while True: time.sleep(60)
except KeyboardInterrupt:
print('\n')
end=time.time()
duration=end-start-latency
values=[duration,duration/60]+[duration/div for div in divs]+[(duration%div)/60 for div in divs]
for msg,value in zip(msgs,values):
value=round(value, 1)
print(msg+':',value)
try:
msg='Press Ctrl+C again in 30 seconds to stop the timer...'
print('\n'+msg,end='')
time.sleep(30)
print('\r'+' '*len(msg)+'\r',end='')
except KeyboardInterrupt: exit('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment