Skip to content

Commit

Permalink
fix flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikelimper committed Oct 18, 2023
1 parent cedce83 commit c2ae90d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions aws-lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
print('Loading function')
s3 = boto3.client('s3')


def handler(event, context):

# Get the object from the event
# Get the object from the event
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8') # noqa
size = event['Records'][0]['s3']['object']['size']
print("object="+key+" received with size="+str(size))
if size == 0:
print("object="+key+" size=0, don't process !")
return 0

filename = key.split('/')[-1]
foldername = key.replace(filename, '')

Expand All @@ -31,17 +32,26 @@ def handler(event, context):

# TODO: read the metadata file from S3
metadata_file = open('/function/station_list.csv', 'r')

nbufr_created = 0
bufr_generator = transform_synop(body, metadata_file.read(), year_utc, month_utc)
bufr_generator = transform_synop(
body,
metadata_file.read(),
year_utc,
month_utc
)
for item in bufr_generator:
if 'bufr4' in item and item['bufr4'] is not None:
identifier = item['_meta']['id']
print('identifier='+identifier)
s3.put_object(Bucket='wis2box-public', Key=foldername+identifier+'.bufr4', Body=item['bufr4'])
s3.put_object(
Bucket='wis2box-public',
Key=foldername+identifier+'.bufr4',
Body=item['bufr4']
)
nbufr_created += 1
else:
print('No BUFR message created for '+item['_meta']['id'])
print('Created '+str(nbufr_created)+' BUFR messages')

return 0
return 0

0 comments on commit c2ae90d

Please sign in to comment.