Allow multiple CSV files; rename nexrad.archive.Archive methods
This commit is contained in:
parent
a6e785281b
commit
e5b24d5d71
2 changed files with 21 additions and 20 deletions
|
@ -14,7 +14,7 @@ parser = argparse.ArgumentParser(
|
||||||
parser.add_argument('--quiet', action='store_true', help='Suppress output')
|
parser.add_argument('--quiet', action='store_true', help='Suppress output')
|
||||||
parser.add_argument('--dry-run', action='store_true', help='Do not actually archive data')
|
parser.add_argument('--dry-run', action='store_true', help='Do not actually archive data')
|
||||||
parser.add_argument('db', help='SQLite3 NEXRAD radar site database')
|
parser.add_argument('db', help='SQLite3 NEXRAD radar site database')
|
||||||
parser.add_argument('csv-report-details', help='Compressed storm report details CSV file')
|
parser.add_argument('csv-report-details', nargs='+', help='Compressed storm report details CSV file')
|
||||||
parser.add_argument('archive-dir', help='Target archive directory')
|
parser.add_argument('archive-dir', help='Target archive directory')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -25,24 +25,25 @@ archive = Archive(getattr(args, 'archive-dir'), bucket)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
for report in StormReport.each_from_csv_file(getattr(args, 'csv-report-details')):
|
for path in getattr(args, 'csv-report-details'):
|
||||||
i += 1
|
for report in StormReport.each_from_csv_file(path):
|
||||||
|
i += 1
|
||||||
|
|
||||||
if not report.is_radar_significant():
|
if not report.is_radar_significant():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
radars = report.nearby_radars(db)
|
radars = report.nearby_radars(db)
|
||||||
|
|
||||||
for key in bucket.each_matching_key(radars, report.timestamp_start, report.timestamp_end):
|
for key in bucket.each_matching_key(radars, report.timestamp_start, report.timestamp_end):
|
||||||
if archive.is_archived(key):
|
if archive.is_downloaded(key):
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
print(f"{key} report {i} Already archived")
|
print(f"{key} report {i} Already archived")
|
||||||
else:
|
else:
|
||||||
if not args.quiet:
|
if not args.quiet:
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
print(f"{key} report {i} Would archive")
|
print(f"{key} report {i} Would archive")
|
||||||
else:
|
else:
|
||||||
print(f"{key} report {i} Archiving")
|
print(f"{key} report {i} Archiving")
|
||||||
|
|
||||||
if not args.dry_run:
|
if not args.dry_run:
|
||||||
archive.archive(key)
|
archive.download(key)
|
||||||
|
|
|
@ -10,10 +10,10 @@ class Archive():
|
||||||
self.path = path
|
self.path = path
|
||||||
self.bucket = bucket
|
self.bucket = bucket
|
||||||
|
|
||||||
def is_archived(self, key: str):
|
def is_downloaded(self, key: str):
|
||||||
return os.path.exists(os.path.join(self.path, key))
|
return os.path.exists(os.path.join(self.path, key))
|
||||||
|
|
||||||
def archive(self, key: str):
|
def download(self, key: str):
|
||||||
path = os.path.join(self.path, key)
|
path = os.path.join(self.path, key)
|
||||||
parent = os.path.dirname(path)
|
parent = os.path.dirname(path)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue