Skip to content

Instantly share code, notes, and snippets.

@harshavardhana
Created November 18, 2017 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshavardhana/1c07ab4666e390215e6a243354da24aa to your computer and use it in GitHub Desktop.
Save harshavardhana/1c07ab4666e390215e6a243354da24aa to your computer and use it in GitHub Desktop.
Watch for CLOSE events and upload the file to S3
import inotify.adapters
from minio import Minio
from minio.error import ResponseError
minioClient = Minio('play.minio.io:9000',
access_key='Q3AM3UQ867SPQQA43P2F',
secret_key='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
secure=True)
def _main():
i = inotify.adapters.Inotify()
i.add_watch(b'/tmp/1')
try:
for event in i.event_gen():
if event is not None:
(header, type_names, watch_path, filename) = event
if type_names[0] is 'IN_CLOSE_WRITE':
print(minioClient.fput_object('testbucket', filename, watch_path+'/'+filename))
finally:
i.remove_watch(b'/tmp/1')
if __name__ == '__main__':
_main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment