Created
November 18, 2017 23:35
-
-
Save harshavardhana/1c07ab4666e390215e6a243354da24aa to your computer and use it in GitHub Desktop.
Watch for CLOSE events and upload the file to S3
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 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