Changes: * Implement config file loader * Add config-based database connector * Remove database path argument from all tools in bin/
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
#! /usr/bin/env python3
 | 
						|
 | 
						|
import argparse
 | 
						|
 | 
						|
from xmet.config import Config
 | 
						|
from xmet.db     import Database
 | 
						|
from xmet.igra   import IGRAReader
 | 
						|
 | 
						|
parser = argparse.ArgumentParser(
 | 
						|
    description = 'Ingest IGRA soundings'
 | 
						|
)
 | 
						|
 | 
						|
parser.add_argument('--quiet',   action='store_true', help='Suppress output')
 | 
						|
parser.add_argument('--dry-run', action='store_true', help='Do not actually ingest data')
 | 
						|
 | 
						|
parser.add_argument('db',                            help='XMET SQLite3 database')
 | 
						|
parser.add_argument('igra-sounding-file', nargs='+', help='IGRA sounding file')
 | 
						|
 | 
						|
args = parser.parse_args()
 | 
						|
 | 
						|
config = Config.load()
 | 
						|
db     = Database.from_config(config)
 | 
						|
 | 
						|
if not args.dry_run:
 | 
						|
    db.execute('begin transaction')
 | 
						|
 | 
						|
for path in getattr(args, 'igra-sounding-file'):
 | 
						|
    if not args.quiet:
 | 
						|
        print(f"Ingesting sounding file {path}")
 | 
						|
 | 
						|
    for sounding in IGRAReader.each_sounding_from_file(path):
 | 
						|
        if args.dry_run:
 | 
						|
            continue
 | 
						|
 | 
						|
        db.add(sounding)
 | 
						|
 | 
						|
        for sample in sounding.samples:
 | 
						|
            sample.sounding_id = sounding.id
 | 
						|
            db.add(sample)
 | 
						|
 | 
						|
if not args.dry_run:
 | 
						|
    db.commit()
 |