Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerize Flexpart and Automate S3 Data Handling for GRIB Input #10

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.py utils as package
  • Loading branch information
ninaburg committed Nov 27, 2024
commit cf03de01622fa196f7724ae7f1d5471c600f66dc
Empty file.
17 changes: 15 additions & 2 deletions upload_s3.py → utils/flexpart_ifs_utils/s3_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python3
import boto3 # pip install boto3
import boto3
import os
import argparse
from datetime import datetime
Expand Down Expand Up @@ -54,3 +53,17 @@ def uploadDirectory(root_path, bucket_name, endpoint_url):
print("Skipping upload to S3 as S3_BUCKET_NAME environment variable is unset.")
else:
uploadDirectory(args.directory, args.bucket, args.endpoint_url)

def download_file(obj, file):
bucket = os.getenv('FLEXPART_S3_BUCKETS__INPUT__NAME')
endpoint_url = os.getenv('FLEXPART_S3_BUCKETS__INPUT__ENDPOINT_URL')

s3 = boto3.client('s3', endpoint_url=endpoint_url, aws_access_key_id=os.getenv('S3_ACCESS_KEY'),
aws_secret_access_key=os.getenv('S3_SECRET_KEY'),)

try:
with open(file, 'wb') as f:
print(f"Downloading {obj} to {f} from bucket: {bucket}")
s3.download_fileobj(bucket, obj, f)
except Exception as e:
raise(e)
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/python3
import os
import yaml
import glob
Expand All @@ -7,27 +6,13 @@
import argparse
import boto3

from flexpart_ifs_utils import s3_utils

try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper


def download_file(obj, file):
bucket = os.getenv('FLEXPART_S3_BUCKETS__INPUT__NAME')
endpoint_url = os.getenv('FLEXPART_S3_BUCKETS__INPUT__ENDPOINT_URL')

s3 = boto3.client('s3', endpoint_url=endpoint_url, aws_access_key_id=os.getenv('S3_ACCESS_KEY'),
aws_secret_access_key=os.getenv('S3_SECRET_KEY'),)

try:
with open(file, 'wb') as f:
print(f"Downloading {obj} to {f} from bucket: {bucket}")
s3.download_fileobj(bucket, obj, f)
except Exception as e:
raise(e)


with open('genconf.yml') as f:
conf: dict = yaml.load(f, Loader=Loader)

Expand Down
Loading