nexrad-archive/lib/nexrad/archive.py
2025-02-11 21:11:43 -05:00

23 lines
563 B
Python

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):
return os.path.exists(self.path + '/' + key)
def archive(self, key: str):
path = 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)