-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlatest.py
More file actions
executable file
·39 lines (32 loc) · 1.23 KB
/
latest.py
File metadata and controls
executable file
·39 lines (32 loc) · 1.23 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
#!/usr/bin/env python3
""" Print the latest date and the month that goes with it, based on
the 'loaded' table.
"""
import tmparms, tmglobals, os, sys, tmutil, MySQLdb
myglobals = tmglobals.tmglobals()
def getlatest(table, conn):
curs = conn.cursor()
# The MySQLdb library doesn't allow interpolating the table name, so we do
# it via normal Python.
district = tmparms.tmparms().district
statement = 'select t.monthstart, l.latest FROM %s t INNER JOIN (select max(loadedfor) as latest FROM loaded WHERE tablename="%s") l ON t.asof = l.latest WHERE district = "%s" GROUP BY t.monthstart, l.latest' % (table, table, district)
try:
curs.execute(statement)
ans = curs.fetchone()
if ans:
ans = [tmutil.stringify(x) for x in ans]
else:
ans = ('', '')
except (MySQLdb.Error, TypeError) as e:
sys.stderr.write(repr(e))
ans = ('', '')
return ans
if __name__ == '__main__':
parms = tmparms.tmparms()
# Allow specifying a table.
parms.add_argument('--table', dest='table', default='clubperf')
# Do global setup
myglobals.setup(parms)
parms.parse()
ans = getlatest(parms.table, myglobals.conn)
print(' '.join(ans))