Created
March 16, 2021 13:01
-
-
Save shortstack/247a3f7cf6a179b299a62e490e0e0390 to your computer and use it in GitHub Desktop.
watch_s3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import boto3 | |
import pytz | |
from datetime import datetime,timedelta | |
from os import path | |
s3 = boto3.resource('s3') | |
s3_client = boto3.client('s3') | |
bucket_name = "mah_bukkit" | |
bucket = s3.Bucket(bucket_name) | |
while True: | |
for key in bucket.objects.all(): | |
time_now = datetime.utcnow().replace(tzinfo=pytz.UTC) | |
delta = time_now - timedelta(seconds=1200) | |
if key.last_modified >= delta and ".zip" in key.key: | |
if path.isfile("/path/to/%s" % key.key): | |
print("File exists, not downloading") | |
else: | |
print("Downloading file: %s" % key.key) | |
s3_client.download_file(bucket_name, key.key, '/path/to/'+key.key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment