<commit_before>"""
Dump iem database of OT data to archive
"""
import mx.DateTime
import sys
import traceback
import iemdb
import psycopg2.extras
OTHER = iemdb.connect('other')
ocursor = OTHER.cursor(cursor_factory=psycopg2.extras.DictCursor)
IEM = iemdb.connect('iem')
icursor = IEM.cursor(cursor_factory=psycopg2.extras.DictCursor)

ts = mx.DateTime.now() - mx.DateTime.RelativeDateTime(days=1)

# Delete any obs from yesterday
sql = "DELETE from t%s WHERE date(valid) = '%s'" % (ts.year, 
      ts.strftime("%Y-%m-%d") )
ocursor.execute(sql)

# Get obs from Access
sql = """SELECT c.*, t.id from current_log c JOIN stations t on 
    (t.iemid = c.iemid) WHERE date(valid) = '%s' 
    and t.network = 'OT'""" % (ts.strftime("%Y-%m-%d"), )
icursor.execute( sql )

for row in icursor:
    pday = 0
    if (row['pday'] is not None and float(row['pday']) > 0):
        pday = row['pday'] 
    alti = row['alti']
    if alti is None and row['mslp'] is not None:
        alti = row['mslp'] * .03 
    sql = """INSERT into t%s (station, valid, tmpf, dwpf, drct, sknt,  alti, 
         pday, gust, c1tmpf,srad) values('%s','%s',%s,%s,%s,%s,%s,%s,%s,%s,%s)
         """ % (ts.year,row['id'], row['valid'], (row['tmpf'] or "Null"), 
  (row['dwpf'] or "Null"), (row['drct'] or "Null"), (row['sknt'] or "Null"),
  (alti or "Null"), pday, (row['gust'] or "Null") , 
   (row['c1tmpf'] or "Null"), (row['srad'] or "Null"))
    icursor.execute(sql)

icursor.close()
IEM.commit()<commit_msg>use the right db cursor<commit_after>"""
Dump iem database of OT data to archive
"""
import mx.DateTime
import sys
import traceback
import iemdb
import psycopg2.extras
OTHER = iemdb.connect('other')
ocursor = OTHER.cursor(cursor_factory=psycopg2.extras.DictCursor)
IEM = iemdb.connect('iem')
icursor = IEM.cursor(cursor_factory=psycopg2.extras.DictCursor)

ts = mx.DateTime.now() - mx.DateTime.RelativeDateTime(days=1)

# Delete any obs from yesterday
sql = "DELETE from t%s WHERE date(valid) = '%s'" % (ts.year, 
      ts.strftime("%Y-%m-%d") )
ocursor.execute(sql)

# Get obs from Access
sql = """SELECT c.*, t.id from current_log c JOIN stations t on 
    (t.iemid = c.iemid) WHERE date(valid) = '%s' 
    and t.network = 'OT'""" % (ts.strftime("%Y-%m-%d"), )
icursor.execute( sql )

for row in icursor:
    pday = 0
    if (row['pday'] is not None and float(row['pday']) > 0):
        pday = row['pday'] 
    alti = row['alti']
    if alti is None and row['mslp'] is not None:
        alti = row['mslp'] * .03 
    sql = """INSERT into t%s (station, valid, tmpf, dwpf, drct, sknt,  alti, 
         pday, gust, c1tmpf,srad) values('%s','%s',%s,%s,%s,%s,%s,%s,%s,%s,%s)
         """ % (ts.year,row['id'], row['valid'], (row['tmpf'] or "Null"), 
  (row['dwpf'] or "Null"), (row['drct'] or "Null"), (row['sknt'] or "Null"),
  (alti or "Null"), pday, (row['gust'] or "Null") , 
   (row['c1tmpf'] or "Null"), (row['srad'] or "Null"))
    ocursor.execute(sql)

ocursor.close()
OTHER.commit()
{'fraction_non_alphanumeric': 0.20107962213225372, 'fraction_numerical': 0.006747638326585695, 'mean_word_length': 3.8686371100164205, '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': '5654262', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1139, 'n_words': 295}