23 lines
580 B
Python
23 lines
580 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_downloaded(self, key: str):
|
|
return os.path.exists(os.path.join(self.path, key))
|
|
|
|
def download(self, key: str):
|
|
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)
|