
from pyIEM import iemAccessDatabase
import os, sys, mx.DateTime
iemdb = iemAccessDatabase.iemAccessDatabase()

dy = int(sys.argv[1])
now = mx.DateTime.now()

sql = "SELECT station, sum(pday) as rain from summary \
  WHERE network = 'KCCI' and \
  day > '%s' and station != 'SCEI4' GROUP by station ORDER by rain DESC" % \
 ( (now - mx.DateTime.RelativeDateTime(days= int(dy) )).strftime("%Y-%m-%d"), )

rs = iemdb.query(sql).dictresult()
dict = {}
dict['dy'] = dy
dict['sid1'] = rs[0]['station']
dict['sid2'] = rs[1]['station']
dict['sid3'] = rs[2]['station']
dict['sid4'] = rs[3]['station']
dict['sid5'] = rs[4]['station']
dict['q'] = "%Q"
dict['fn'] = "Last %s Day Precip" % (dy,)
if dy == 2:
  dict['title'] = "TWO DAY RAINFALL"
if dy == 3:
  dict['title'] = "3 DAY RAINFALL"
if dy == 7:
  dict['title'] = "7 DAY RAINFALL"
if dy == 14:
  dict['title'] = "14 DAY RAINFALL"

out = open('top5rain%sday.scn' % (dy,), 'w')


out.write( open('top5rain2day.tpl','r').read() % dict )

out.close()

os.system("/home/ldm/bin/pqinsert top5rain%sday.scn" % (dy,))

@@ -1,40 +1,4 @@
-%0Afrom pyIEM import iemAccessDatabase
 %0Aimp
@@ -21,16 +21,20 @@
 DateTime
+, pg
 %0Aiemdb =
@@ -38,44 +38,48 @@
 b = 
-iemAccessDatabase.iemAccessDatabase(
+pg.connect('iem', 'iemdb', user='nobody'
 )%0A%0Ad
@@ -586,24 +586,62 @@
 %5B'station'%5D%0A
+dict%5B'timestamp'%5D = mx.DateTime.now()%0A
 dict%5B'q'%5D = 

fix to include timestamp