Problem:
You need to download a huge list of images from amazon and the list is in a data base table.
You need to download a huge list of images from amazon and the list is in a data base table.
Solution:
You can create an easy script using request to access to the image url and shutil to copy one by one each image.
import mysql.connector
import shutil
import requests
conn = mysql.connector.connect(
host="localhost",
user="usuario",
password="******",
database="DBIMAGES"
)
cursor = conn.cursor()
cursor.execute('SELECT * FROM z_images ORDER')
rows = cursor.fetchall()
for row in rows:
resp = requests.get(row[4], stream=True)
path = row[4]
firstpos = path.rfind("/")+1
lastpos=len(path)
v_filename = path[firstpos:lastpos]
local_file = "/home/img/"+v_filename
with open(local_file, 'wb') as out_file:
shutil.copyfileobj(resp.raw, out_file)
print(v_filename)
print("END")