diff --git a/src/app.py b/src/app.py index 9cde5c3..be58867 100644 --- a/src/app.py +++ b/src/app.py @@ -27,10 +27,13 @@ def worker(): filename = "{}@{}.json".format(account_info["username"], domain).lower() filepath = os.path.join(base_dir, os.path.basename(filename.lower())) + now = datetime.datetime.now().timestamp() if is_lambda: - s3.get_file(filename, filepath) + _, last_modified = s3.get_file(filename, filepath) + else: + last_modified = os.path.getmtime(filepath) if os.path.isfile(filepath) else None - if (os.path.isfile(filepath) and datetime.datetime.now().timestamp() - os.path.getmtime(filepath) < 60 * 60 * 24): + if (os.path.isfile(filepath) and last_modified is not None and now - last_modified < 60 * 60 * 24): print("モデルは再生成されません") else: exportModel.generateAndExport(mastodonTool.loadMastodonAPI(domain, read_access_token, account_info['id'], params), filepath) diff --git a/src/s3.py b/src/s3.py index 3030fe5..3545adb 100644 --- a/src/s3.py +++ b/src/s3.py @@ -9,12 +9,14 @@ def get_file(key, file_path): try: - s3.Bucket(os.environ["S3_BUCKET"]).download_file(key, file_path) + bucketName = os.environ["S3_BUCKET"] + object_summery = s3.ObjectSummary(bucketName, key) + s3.Bucket(bucketName).download_file(key, file_path) print("File downloaded: {} to {}".format(key, file_path)) + return True, object_summery.last_modified.timestamp() except ClientError: print("File not found: {}".format(key)) - return False - return True + return False, None def put_file(key, file_path):