countdown/countdown.py

29 lines
915 B
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python3
import datetime
import sys
import locale
locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8")
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 ("До " + datetime.datetime.strftime(future, "%d %B %Y года %H:%M") + " осталось " + str(days) + " дней " + str(hours))