forked from d101tm/tmstats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequire.py
More file actions
executable file
·98 lines (76 loc) · 3.31 KB
/
require.py
File metadata and controls
executable file
·98 lines (76 loc) · 3.31 KB
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
#!/usr/bin/env python3
""" Require certain conditions
Sets the return code to 0 if all required conditions are true, else sets to 1
"""
import tmutil, sys, datetime
import tmglobals
myglobals = tmglobals.tmglobals()
def cleandate(s):
return datetime.datetime.strptime(tmutil.cleandate(s, usetmyear=False), '%Y-%m-%d').date()
def datacheck(s):
s = s.lower()
if s.startswith('s') or s.startswith('m'):
month = int(s[1:])
# Compute the month to check:
year = myglobals.tmyear if month >= 7 else myglobals.tmyear + 1
start = "monthstart = '%d-%0.2d-01'" % (year, month)
# Do we need final for the month?
final = " AND ENTRYTYPE = 'M'" if s.startswith('m') else ''
# See if we've got it
myglobals.curs.execute('SELECT COUNT(*) FROM clubperf WHERE ' + start + final)
else:
# We have a specific date
myglobals.curs.execute('SELECT COUNT(*) FROM clubperf WHERE ASOF = %s', (cleandate(s),))
res = curs.fetchone()[0]
if res > 0:
return True
else:
return False
### Insert classes and functions here. The main program begins in the "if" statement below.
if __name__ == "__main__":
import tmparms
# Establish parameters
parms = tmparms.tmparms()
# Add other parameters here
group = parms.add_argument_group('calendar parms')
group.add_argument('--starting', type=str, help='First date this is true')
group.add_argument('--ending', type=str, help='Last date this is true')
group.add_argument('--between', type=str, nargs=2, help='First and last dates')
group = parms.add_argument_group('database parms', 'Specify Mn if month "n" must be complete; specify Sn if month "n" must be started.')
group.add_argument('--datafor', type=str, help='Date or Month for which data must be available.')
group.add_argument('--nodatafor', type=str, help='Date or Month for which data must NOT be available.')
group = parms.add_argument_group('TM Year parms')
group.add_argument('--newtmyear', action='store_true', help='Data is available for the TM Year beginning July 1 of this calendar year')
group.add_argument('--oldtmyear', action='store_true', help='Data is NOT available for the TM Year beginning July 1 of this calendar year')
# Do global setup
myglobals.setup(parms)
curs = myglobals.curs
conn = myglobals.conn
today = myglobals.today
if parms.starting:
starting = cleandate(parms.starting)
if today < starting:
sys.exit(1)
if parms.ending:
ending = cleandate(parms.ending)
if today > ending:
sys.exit(2)
if parms.between:
starting = cleandate(parms.between[0])
ending = cleandate(parms.between[1])
if ending < starting:
ending = ending.replace(ending.year+1)
if today < starting or today > ending:
sys.exit(3)
if parms.datafor:
if not datacheck(parms.datafor):
sys.exit(4)
if parms.nodatafor:
if datacheck(parms.nodatafor):
sys.exit(5)
if parms.newtmyear:
if myglobals.today.year != myglobals.tmyear:
sys.exit(6)
if parms.oldtmyear:
if myglobals.today.year == myglobals.tmyear:
sys.exit(7)