Skip to content

Commit

Permalink
extract any date format and collision check
Browse files Browse the repository at this point in the history
  • Loading branch information
Cinzia Malangone committed Apr 1, 2020
1 parent f07e243 commit c69e091
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions modules/GoogleBucketResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,23 @@ def extract_date_from_file(self, filename):

def extract_latest_file(self, list_blobs):
last_recent_file = None
possible_recent_date_collision = False
recent_date = datetime.strptime('01-01-1900', '%d-%m-%Y')
for filename in list_blobs:
date_file = self.extract_date_from_file(filename)
if date_file:
if date_file == recent_date:
# Raise an error
logger.error("Error TWO files with the same date: %s %s", last_recent_file, recent_date.strftime('%d-%m-%Y'))
exit(1)
possible_recent_date_collision = True
if date_file > recent_date:
possible_recent_date_collision = False
recent_date = date_file
last_recent_file = filename

if possible_recent_date_collision:
# Raise an error
logger.error("Error TWO files with the same date: %s %s", last_recent_file,
recent_date.strftime('%d-%m-%Y'))
exit(1)
logger.info("Latest file: %s %s", last_recent_file, recent_date.strftime('%d-%m-%Y'))
return {"latest_filename": last_recent_file, "suffix": recent_date.strftime('%Y-%m-%d')}

Expand Down

0 comments on commit c69e091

Please sign in to comment.