initial version

This commit is contained in:
Rinaldus 2018-07-11 12:22:40 +03:00
commit 41ecdae7b5
Signed by: Rinaldus
GPG Key ID: C34E249005178E87
2 changed files with 35 additions and 0 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# Countdown
Calculates time difference between 2 dates.
## Usage
Simply type
`python3 countdown.py [DATE] [TIME]`
where `DATE` is date in format DD.MM.YY and `TIME` is time in format HH:MM

26
countdown.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/python3
import datetime
import sys
now = datetime.datetime.now()
if (len(sys.argv) < 2):
kb = input ("Введите дату в формате ДЕНЬ.МЕСЯЦ.ГОД: ")
tm = input ("Введите время в формате ЧЧ:ММ (необязательно) ")
else:
kb = sys.argv[1]
if (len(sys.argv) >= 3):
tm = sys.argv[2]
else:
tm = "00:00"
ar = kb.split(".")
if (tm):
ar2 = tm.split(":")
else:
ar2 = [0, 0]
future = datetime.datetime(int(ar[2]),int(ar[1]),int(ar[0]),int(ar2[0]),int(ar2[1]))
result = future - now
days = result.days
hours = datetime.datetime.strftime((datetime.datetime.utcfromtimestamp(result.seconds)), "%H:%M:%S")
print ("До указанной даты осталось " + str(days) + " дней " + str(hours))