#NEWLINE# def ingest( dbname , filename , dt , lt , cname , stname ) : #NEWLINE# #INDENT# 'Imports Geotif *filename* into database *db*.' #NEWLINE# db = dbio . connect ( dbname ) #NEWLINE# cur = db . cursor ( ) #NEWLINE# ( schemaname , tablename ) = stname . split ( '.' ) #NEWLINE# cur . execute ( "select * from information_schema.tables where table_schema='{0}' and table_name='{1}'" . format ( schemaname , tablename ) ) #NEWLINE# if ( not bool ( cur . rowcount ) ) : #NEWLINE# #INDENT# cur . execute ( 'create table {0}.{1} (rid serial not null primary key, fdate date, tercile text, leadtime int, rast raster)' . format ( schemaname , tablename ) ) #NEWLINE# db . commit ( ) #NEWLINE# #UNINDENT# cur . execute ( "select * from {0} where fdate='{1}'" . format ( stname , dt . strftime ( '%Y-%m-%d' ) ) ) #NEWLINE# if bool ( cur . rowcount ) : #NEWLINE# #INDENT# cur . execute ( "delete from {0} where fdate='{1}'" . format ( stname , dt . strftime ( '%Y-%m-%d' ) ) ) #NEWLINE# db . commit ( ) #NEWLINE# #UNINDENT# dbio . ingest ( dbname , filename , dt , stname , False , False ) #NEWLINE# sql = "update {0} set tercile = '{1}' where tercile is null" . format ( stname , cname ) #NEWLINE# cur . execute ( sql ) #NEWLINE# sql = "update {0} set leadtime = '{1}' where leadtime is null" . format ( stname , lt ) #NEWLINE# cur . execute ( sql ) #NEWLINE# db . commit ( ) #NEWLINE# cur . close ( )