-
Notifications
You must be signed in to change notification settings - Fork 39
/
days-until
executable file
·36 lines (28 loc) · 971 Bytes
/
days-until
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
#!/usr/bin/env python
# -*- coding: utf-8; -*-
#_____________________________________________________________________________
#
# days-until
# ----------
# Prints the number of days remaining until some event.
#
# Usage: $ days-until 'the eschaton' 2012-06-21
#_____________________________________________________________________________
from datetime import date
import sys
def days_until(when):
year, month, day = when.split('-', 3)
remaining = date(int(year), int(month), int(day)) - date.today()
return remaining.days
if __name__ == "__main__":
message = None
if len(sys.argv) == 3:
when = sys.argv[2]
message = sys.argv[1]
elif len(sys.argv) == 2:
when = sys.argv[1]
else:
sys.stdout.write("Usage: %s [MESSAGE] YEAR-MONTH-DAY\n" % __file__)
remaining = days_until(when)
sys.stdout.write("Days remaining until %s: %d\n" %
(message if message else "event", remaining))