Initial commit of nexrad-archive-report-ingest
This commit is contained in:
parent
070f04b469
commit
db8ed2142d
1 changed files with 35 additions and 0 deletions
35
bin/nexrad-archive-report-ingest
Executable file
35
bin/nexrad-archive-report-ingest
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
from nexrad.db import Database
|
||||||
|
from nexrad.storm import StormReport
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description = 'Ingest reports from StormEvent_details_*.csv.gz files'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('--quiet', action='store_true', help='Suppress output')
|
||||||
|
parser.add_argument('--dry-run', action='store_true', help='Do not actually ingest reports')
|
||||||
|
parser.add_argument('db', help='SQLite3 NEXRAD radar site database')
|
||||||
|
parser.add_argument('csv-report-details', nargs='+', help='Compressed storm report details CSV file')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
db = Database.connect(args.db)
|
||||||
|
|
||||||
|
if not args.dry_run:
|
||||||
|
db.execute('begin transaction')
|
||||||
|
|
||||||
|
for path in getattr(args, 'csv-report-details'):
|
||||||
|
for report in StormReport.each_from_csv_file(path):
|
||||||
|
print(f"Report ID {report.id}")
|
||||||
|
|
||||||
|
if not args.dry_run:
|
||||||
|
db.add(report)
|
||||||
|
|
||||||
|
if not args.quiet:
|
||||||
|
print(f"Finished ingesting file {path}")
|
||||||
|
|
||||||
|
if not args.dry_run:
|
||||||
|
db.commit()
|
Loading…
Add table
Reference in a new issue