andrewb icon

dl.py

andrewb | PRO | 06/27/16 12:10:41 AM UTC | 0 ⭐ | 886 👁️ | Never ⏰ | []
Python |

440 B

|

None

|

0 👍

/

0 👎

import urllib3, sys, boto3
 
bucket_name = sys.argv[2]
url = sys.argv[1]
file = url.split('/')[-1:][0]
ext = file.split('.')[-1:][0]
 
http = urllib3.PoolManager(cert_reqs=None)
r = http.request('GET', url)
 
with open(file, 'wb') as the_file:
    the_file.write(r.data)
 
s3 = boto3.client('s3')
s3.upload_file(file, bucket_name, file,
               ExtraArgs={'ACL': 'public-read',
                          'ContentType':'image/'+ext})

Comments