'''
 Some of our solar radiation data is not good!
'''
import psycopg2
ISUAG = psycopg2.connect(database='isuag', host='iemdb', user='nobody')
cursor = ISUAG.cursor()

def main():
    ''' Go main go '''
    cursor.execute("""
     SELECT station, yr, mo from 
      (select station, extract(year from valid) as yr, 
      extract(month from valid) as mo, sum(c80) from daily 
      GROUP by station, yr, mo) as foo
     WHERE sum < 100
    """)
    for row in cursor:
        print 'Reprocess %s %i-%02i' % (row[0], row[1], row[2])
        

if __name__ == '__main__':
    main()
@@ -1,11 +1,11 @@
-'''
+%22%22%22
 %0A Some o
@@ -44,19 +44,19 @@
 t good!%0A
-'''
+%22%22%22
 %0Aimport 
@@ -64,16 +64,32 @@
 sycopg2%0A
+import datetime%0A
 ISUAG = 
@@ -176,16 +176,42 @@
 ursor()%0A
+cursor2 = ISUAG.cursor()%0A%0A
 %0Adef mai
@@ -219,19 +219,19 @@
 ():%0A    
-'''
+%22%22%22
  Go main
@@ -238,11 +238,11 @@
  go 
-'''
+%22%22%22
 %0A   
@@ -286,237 +286,535 @@
 on, 
-yr, mo from %0A      (select station, extract(year from valid) as yr, %0A      extract(month from valid) as mo, sum(c80) from daily %0A      GROUP by station, yr, mo) as foo%0A     WHERE sum %3C 100%0A    %22%22%22
+valid from sm_daily where slrmj_tot is null or%0A     slrmj_tot = 0 and valid %3E '2015-04-14' ORDER by valid ASC%0A    %22%22%22)%0A    for row in cursor:%0A        station = row%5B0%5D%0A        v1 = datetime.datetime(row%5B1%5D.year, row%5B1%5D.month, row%5B1%5D.day)%0A        v2 = v1.replace(hour=23, minute=59)%0A        cursor2.execute(%22%22%22%0A        SELECT sum(slrmj_tot), count(*) from sm_hourly WHERE%0A        station = %25s and valid %3E= %25s and valid %3C %25s%0A        %22%22%22, (station, v1, v2)
 )%0A    
-for
+   
  row
- in
+2 =
  cursor
-:%0A
+2.fetchone()%0A        if row2%5B0%5D is None:%0A   
         
 prin
@@ -813,51 +813,227 @@
     
+ 
 print
- 'Reprocess %25s %25i-%2502i' %25 (
+('Double Failure %25s %25s' %25 (station, v1.strftime(%22%25d %25b %25Y%22)))%0A            continue%0A        print('%25s %25s -%3E %25.2f (%25s obs)' %25 (station, v1.strftime(%22%25d %25b %25Y%22),%0A                                          
 row
+2
 %5B0%5D, row
 %5B1%5D,
@@ -1032,29 +1032,190 @@
  row
+2
 %5B1%5D
+))%0A        cursor2.execute(%22%22%22UPDATE sm_daily SET slrmj_tot = %25s%0A        WHERE station = %25s and valid = %25s%22%22%22
 , 
+(
 row
-%5B2%5D)%0A        
+2%5B0%5D, station, row%5B1%5D))%0A%0A    cursor2.close()%0A    ISUAG.commit()
 %0A%0Aif
@@ -1245,12 +1245,13 @@
 :%0A    main()
+%0A

repair missing daily ISUSM solar radiation data