Skip to content

Instantly share code, notes, and snippets.

@shortstack
Created March 16, 2021 13:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shortstack/247a3f7cf6a179b299a62e490e0e0390 to your computer and use it in GitHub Desktop.
Save shortstack/247a3f7cf6a179b299a62e490e0e0390 to your computer and use it in GitHub Desktop.
watch_s3.py
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