-
Notifications
You must be signed in to change notification settings - Fork 1
/
insert_entry.py
executable file
·140 lines (128 loc) · 3.13 KB
/
insert_entry.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python3
# Copyright (C) 2009-2017 Serge Hallyn <serge@hallyn.com>
import datetime
import os
import string
import sys
import time
debug = False
doall=False
curday=int(time.strftime("%d"))
try:
if os.getenv("TICKLER_DOALL", "no") == "yes":
doall=True
except:
pass
def skipday(day):
if doall == False and day < curday:
return True
return False
def process_bydate(line):
day = int(line[0])
desc = " ".join(line[1:])
if skipday(day):
return
filename = "%02d" % day
if debug:
print("opening (by date) %s" % filename)
f = open(filename, "a")
f.writelines(["XXX %s XXX\n" % desc])
f.close()
dayhash = { 'M': 1, 'Mon': 1,'Monday': 1,
'T': 2, 'Tue': 2, 'Tuesday': 2,
'W': 3, 'Wed': 3, 'Wednesday': 3,
'R': 4, 'Tr': 4, 'Thur': 4, 'Thurs': 4, 'Thursday': 4,
'F': 5, 'Fri': 5, 'Friday': 5,
'Sat': 6, 'Saturday': 6,
'Sun': 7, 'Sunday': 7 }
def process_monthly(line):
day = line[0]
wk = line[1]
start = line[2]
end = line[3]
desc = " ".join(line[4:])
today = time.localtime()
y = today[0]
m = today[1]
firstdayofmonth = int(datetime.datetime(y, m, 1).strftime("%w"))
if debug:
print("firstdayofmonth is %d" % firstdayofmonth)
tmp = dayhash[day] - firstdayofmonth + 1
if debug:
print("tmp is now %d" % tmp)
if (firstdayofmonth > dayhash[day]):
tmp += 7
tmp += (int(wk)-1)*7
if skipday(tmp):
return
filename = "%02d" % tmp
if debug:
print("my line was : %s" % str(line))
print("so i'm opening : %s" % filename)
f = open(filename, "a")
f.writelines(["XXX %s-%s: %s XXX\n" % (start, end, desc)])
f.close()
months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]
def process_annual(line):
if debug:
print("here I am with %s " % line)
month = line[0]
date = line[1]
desc = " ".join(line[2:])
today = time.localtime()
y = today[0]
m = today[1]
if months[m-1] != month:
return
day = int(date)
if skipday(day):
return
filename = "%02d" % day
if debug:
print("my line was : %s" % str(line))
print("so i'm opening : %s" % filename)
f = open(filename, "a")
f.writelines(["XXX %s XXX\n" % (desc)])
f.close()
def process_weekly(line):
day = line[0]
start = line[1]
end = line[2]
desc = " ".join(line[3:])
today = time.localtime()
y = today[0]
m = today[1]
firstdayofmonth = int(datetime.datetime(y, m, 1).strftime("%w"))
if debug:
print("firstdayofmonth is %d" % firstdayofmonth)
tmp = dayhash[day] - firstdayofmonth + 1
if debug:
print("tmp is now %d" % tmp)
if (firstdayofmonth > dayhash[day]):
tmp += 7
if debug:
print("tmp is now %d" % tmp)
while tmp <= 31:
if skipday(tmp):
tmp += 7
continue
filename = "%02d" % tmp
if debug:
print("my line was : %s" % str(line))
print("so i'm opening : %s" % filename)
f = open(filename, "a")
f.writelines(["XXX %s-%s: %s XXX\n" % (start, end, desc)])
f.close()
tmp += 7
a = sys.argv
type = a[1]
if type == 'M':
process_monthly(a[2:])
elif type == 'D':
process_bydate(a[2:])
elif type == 'W':
process_weekly(a[2:])
elif type == 'A' or type == 'Y':
process_annual(a[2:])
else:
print("I don't know how to handle this entry: %s" % str(sys.argv[1:]))