<commit_before>

import os
import subprocess
import datetime
import sys
import tempfile
import tracker
qc = tracker.loadqc()
import iemdb
IEM = iemdb.connect("iem", bypass=True)
icursor = IEM.cursor()

icursor.execute("""SELECT t.id as station from current c, stations t 
  WHERE t.network = 'KCCI' and 
  t.iemid = c.iemid and valid > 'TODAY' ORDER by pday DESC""")
data = {}

data['timestamp'] = datetime.datetime.now()
i = 1
for row in icursor:
    if i == 6:
        break
    if qc.get(row[0], {}).get('tmpf', False):
        continue
    data['sid%s' % (i,)] = row[0]
    i += 1

if i == 1:
    sys.exit()

fd, path = tempfile.mkstemp()
os.write(fd,  open('top5rain.tpl','r').read() % data )
os.close(fd)

subprocess.call("/home/ldm/bin/pqinsert -p 'auto_top5rain.scn' %s" % (path,),
                shell=True)
os.remove(path)
<commit_msg>some cleanups, prevent error at midnight, use right QC flag<commit_after>'''
 Generate top 5 rainfall reports scene for WXC
'''
import os
import subprocess
import datetime
import sys
import tempfile
import tracker
qc = tracker.loadqc()
import psycopg2
IEM = psycopg2.connect(database='iem', host='iemdb', user='nobody')
icursor = IEM.cursor()

icursor.execute("""SELECT t.id as station from current c, stations t 
  WHERE t.network = 'KCCI' and 
  t.iemid = c.iemid and valid > 'TODAY' ORDER by pday DESC""")
data = {}

data['timestamp'] = datetime.datetime.now()
i = 1
for row in icursor:
    if i == 6:
        break
    if qc.get(row[0], {}).get('precip', False):
        continue
    data['sid%s' % (i,)] = row[0]
    i += 1

if i == 1 or not data.has_key('sid5'):
    sys.exit()

fd, path = tempfile.mkstemp()
os.write(fd,  open('top5rain.tpl','r').read() % data )
os.close(fd)

subprocess.call("/home/ldm/bin/pqinsert -p 'auto_top5rain.scn' %s" % (path,),
                shell=True)
os.remove(path)

{'fraction_non_alphanumeric': 0.16090712742980562, 'fraction_numerical': 0.01079913606911447, 'mean_word_length': 3.475845410628019, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '226594', 'n_tokens_mistral': 716, 'n_tokens_neox': 681, 'n_words': 191}