nexrad-archive/lib/nexrad/archive.py

24 lines
577 B
Python
Raw Normal View History

import os
from nexrad.s3 import S3Bucket
class Archive():
path: str
bucket: S3Bucket
def __init__(self, path: str, bucket: S3Bucket):
self.path = path
self.bucket = bucket
def is_archived(self, key: str):
2025-02-12 15:37:14 -05:00
return os.path.exists(os.path.join(self.path, key))
def archive(self, key: str):
2025-02-12 15:37:14 -05:00
path = os.path.join(self.path, key)
parent = os.path.dirname(path)
os.makedirs(parent, exist_ok=True)
with open(path, 'wb') as fh:
self.bucket.s3.download_fileobj(self.bucket.name, key, fh)